Created
October 25, 2022 13:00
-
-
Save xh3b4sd/9bff3ce1b98287fd9521b724a86297c8 to your computer and use it in GitHub Desktop.
golang bit operators
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 ( | |
"encoding/binary" | |
"fmt" | |
) | |
func main() { | |
var zer byte = 0b0 | |
var one byte = 0b1 | |
fmt.Printf("zer %b\n", zer) | |
fmt.Printf("one %b\n", one) | |
fmt.Printf("\n") | |
fmt.Printf("one & one %b\n", one&one) | |
fmt.Printf("one & zer %b\n", one&zer) | |
fmt.Printf("zer & one %b\n", zer&one) | |
fmt.Printf("zer & zer %b\n", zer&zer) | |
fmt.Printf("\n") | |
fmt.Printf("one | one %b\n", one|one) | |
fmt.Printf("one | zer %b\n", one|zer) | |
fmt.Printf("zer | one %b\n", zer|one) | |
fmt.Printf("zer | zer %b\n", zer|zer) | |
fmt.Printf("\n") | |
fmt.Printf("one ^ one %b\n", one^one) | |
fmt.Printf("one ^ zer %b\n", one^zer) | |
fmt.Printf("zer ^ one %b\n", zer^one) | |
fmt.Printf("zer ^ zer %b\n", zer^zer) | |
fmt.Printf("\n") | |
fmt.Printf("size zer %d\n", binary.Size(zer)) | |
fmt.Printf("size one %d\n", binary.Size(one)) | |
} |
Author
xh3b4sd
commented
Oct 25, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment