github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/pkg/bits/bits32.go (about) 1 package bits 2 3 // IsOn returns true if *all* bits set in 'bits' are set in 'mask'. 4 func IsOn32(mask, bits uint32) bool { 5 return mask&bits == bits 6 } 7 8 // IsAnyOn returns true if *any* bit set in 'bits' is set in 'mask'. 9 func IsAnyOn32(mask, bits uint32) bool { 10 return mask&bits != 0 11 } 12 13 // Mask returns a T with all of the given bits set. 14 func Mask32(is ...int) uint32 { 15 ret := uint32(0) 16 for _, i := range is { 17 ret |= MaskOf32(i) 18 } 19 return ret 20 } 21 22 // MaskOf is like Mask, but sets only a single bit (more efficiently). 23 func MaskOf32(i int) uint32 { 24 return uint32(1) << uint32(i) 25 } 26 27 // IsPowerOfTwo returns true if v is power of 2. 28 func IsPowerOfTwo32(v uint32) bool { 29 if v == 0 { 30 return false 31 } 32 return v&(v-1) == 0 33 }