package main
import (
"fmt"
)
func main() {
a := 13 // 00001101
b := 10 // 00001010
and := a & b // AND operation
or := a | b // OR operation
xor := a ^ b // XOR operation
not := ^a // NOT operation
leftShift := a << 1 // Left shift by 1
rightShift := a >> 2 // Right shift by 2
fmt.Printf("AND result: %d (%.8b)\n", and, and)
fmt.Printf("OR result: %d (%.8b)\n", or, or)
fmt.Printf("XOR result: %d (%.8b)\n", xor, xor)
fmt.Printf("NOT a result: %d (%.8b)\n", not, uint8(not))
fmt.Printf("Left shift a by 1: %d (%.8b)\n", leftShift, leftShift)
fmt.Printf("Right shift a by 2: %d (%.8b)\n", rightShift, rightShift)
}
and := a & b // AND operation
combine bits keeping 1 only where both bits are 1
or := a | b // OR operation
combine bits keeping 1 where either bit is 1
xor := a ^ b // XOR operation
combine bits keeping 1 where bits differ
not := ^a // NOT operation
flip all bits of a
leftShift := a << 1 // Left shift by 1
move bits left by 1, add 0 on right
rightShift := a >> 2 // Right shift by 2
move bits right by 2, drop bits on right
AND result: 8 (00001000)
OR result: 15 (00001111)
XOR result: 7 (00000111)
NOT a result: -14 (11110010)
Left shift a by 1: 26 (00011010)
Right shift a by 2: 3 (00000011)