File: bits32.go

package info (click to toggle)
golang-inet-netstack 0.0~git20211120.8aa80cf2-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 4,512 kB
  • sloc: asm: 900; makefile: 4
file content (33 lines) | stat: -rw-r--r-- 725 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package bits

// IsOn returns true if *all* bits set in 'bits' are set in 'mask'.
func IsOn32(mask, bits uint32) bool {
	return mask&bits == bits
}

// IsAnyOn returns true if *any* bit set in 'bits' is set in 'mask'.
func IsAnyOn32(mask, bits uint32) bool {
	return mask&bits != 0
}

// Mask returns a T with all of the given bits set.
func Mask32(is ...int) uint32 {
	ret := uint32(0)
	for _, i := range is {
		ret |= MaskOf32(i)
	}
	return ret
}

// MaskOf is like Mask, but sets only a single bit (more efficiently).
func MaskOf32(i int) uint32 {
	return uint32(1) << uint32(i)
}

// IsPowerOfTwo returns true if v is power of 2.
func IsPowerOfTwo32(v uint32) bool {
	if v == 0 {
		return false
	}
	return v&(v-1) == 0
}