How to create a bitset in Go

1 Answer

0 votes
package main

import (
	"fmt"
)

func main() {
	var bitset uint32

	// Set bit at position 5
	bitset |= 1 << 5

	// Check if bit at position 5 is set
	isSet := bitset&(1 << 5) != 0

	fmt.Printf("Bitset: %064b\n", bitset)
	fmt.Printf("Is bit 5 set? %v\n", isSet)

	// Clear bit at position 5
	bitset &^= 1 << 5

	fmt.Printf("Bitset after clearing bit 5: %064b\n", bitset)
}

 
 
/*
run:
 
Bitset: 0000000000000000000000000000000000000000000000000000000000100000
Is bit 5 set? true
Bitset after clearing bit 5: 0000000000000000000000000000000000000000000000000000000000000000

*/

 



answered May 7 by avibootz
...