Created
July 12, 2016 15:06
-
-
Save tscolari/2e664b380f6ab1790ed37e6bfefe9451 to your computer and use it in GitHub Desktop.
sample to check if the `n` bit of a `a` byte is true or false
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
var a byte | |
a = 0x02 | |
fmt.Printf("%08b\n", a) | |
n := 1 | |
_bit := uint32(n % 8) | |
b := ((a & (1 << _bit)) != 0) | |
fmt.Println("!", b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment