diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-03-25 22:03:34 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-03-25 22:03:34 +0000 |
commit | 0a1754d8a16af9db032c0c367ac4599daf8e2475 (patch) | |
tree | e236c9524481b6fadfed24fa304829916605a7b6 /pkg/bits | |
parent | 91403113dded391bec07350f77e404096c490e0d (diff) | |
parent | e541ebec2fdb5b29209cb3fc8235b77edcaebb6a (diff) |
Merge release-20200219.0-228-ge541ebe (automated)
Diffstat (limited to 'pkg/bits')
-rwxr-xr-x | pkg/bits/bits32.go | 8 | ||||
-rwxr-xr-x | pkg/bits/bits64.go | 8 |
2 files changed, 16 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 +} diff --git a/pkg/bits/bits64.go b/pkg/bits/bits64.go index f49158792..73117b19b 100755 --- a/pkg/bits/bits64.go +++ b/pkg/bits/bits64.go @@ -23,3 +23,11 @@ func Mask64(is ...int) uint64 { func MaskOf64(i int) uint64 { return uint64(1) << uint64(i) } + +// IsPowerOfTwo returns true if v is power of 2. +func IsPowerOfTwo64(v uint64) bool { + if v == 0 { + return false + } + return v&(v-1) == 0 +} |