diff options
Diffstat (limited to 'pkg/bits/bits32.go')
-rwxr-xr-x | pkg/bits/bits32.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/pkg/bits/bits32.go b/pkg/bits/bits32.go index 4e9e45dce..28134a9e7 100755 --- a/pkg/bits/bits32.go +++ b/pkg/bits/bits32.go @@ -23,3 +23,11 @@ func Mask32(is ...int) uint32 { 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 +} |