Skip to content

Instantly share code, notes, and snippets.

@tscolari
Created July 12, 2016 15:06
Show Gist options
  • Save tscolari/2e664b380f6ab1790ed37e6bfefe9451 to your computer and use it in GitHub Desktop.
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
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