How to use right and left shift in Go

1 Answer

0 votes
package main

import "fmt"

func main() {
	a := 3
	
	a = 3 << 5 // 3 * 2 (6) * 2 (12) * 2 (24) * 2 (48) * 2 (96) (5 times 2)
	fmt.Println(a)
	
	a = a >> 3 // 96 / 2 (48) / 2 (24) / 2 (12) (3 time 2)
	fmt.Println(a)
}


/*
run:

96
12

*/

 



answered Mar 2, 2020 by avibootz
...