diff options
Diffstat (limited to 'bitwise.go')
-rw-r--r-- | bitwise.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/bitwise.go b/bitwise.go new file mode 100644 index 0000000..b9b6f47 --- /dev/null +++ b/bitwise.go @@ -0,0 +1,21 @@ +package main + +func validateBitZeros(bs []byte, n uint) bool { + q := n / 8 + r := n % 8 + + for i := uint(0); i < q; i++ { + if bs[i] != 0 { + return false + } + } + + if r > 0 { + mask := byte(0xFF << (8 - r)) + if bs[q]&mask != 0 { + return false + } + } + + return true +} |