| 1 | package bits |
| 2 | |
| 3 | // IsOn returns true if *all* bits set in 'bits' are set in 'mask'. |
| 4 | func IsOn64(mask, bits uint64) bool { |
| 5 | return mask&bits == bits |
| 6 | } |
| 7 | |
| 8 | // IsAnyOn returns true if *any* bit set in 'bits' is set in 'mask'. |
| 9 | func IsAnyOn64(mask, bits uint64) bool { |
| 10 | return mask&bits != 0 |
| 11 | } |
| 12 | |
| 13 | // Mask returns a T with all of the given bits set. |
| 14 | func Mask64(is ...int) uint64 { |
| 15 | ret := uint64(0) |
| 16 | for _, i := range is { |
| 17 | ret |= MaskOf64(i) |
| 18 | } |
| 19 | return ret |
| 20 | } |
| 21 | |
| 22 | // MaskOf is like Mask, but sets only a single bit (more efficiently). |
| 23 | func MaskOf64(i int) uint64 { |
| 24 | return uint64(1) << uint64(i) |
| 25 | } |
| 26 | |
| 27 | // IsPowerOfTwo returns true if v is power of 2. |
| 28 | func IsPowerOfTwo64(v uint64) bool { |
| 29 | if v == 0 { |
| 30 | return false |
| 31 | } |
| 32 | return v&(v-1) == 0 |
| 33 | } |