aboutsummaryrefslogtreecommitdiff
path: root/bitwise.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-23 12:01:36 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-23 12:01:36 +0800
commit71559a48afc860d124b4ddfeb8df752b22a25053 (patch)
treea163ec0a7c0d811bf39ab8e943ee76a87a95ef41 /bitwise.go
parentReorganize README (diff)
downloadpowxy-71559a48afc860d124b4ddfeb8df752b22a25053.tar.gz
powxy-71559a48afc860d124b4ddfeb8df752b22a25053.tar.zst
powxy-71559a48afc860d124b4ddfeb8df752b22a25053.zip
Separate validateBitZeros into a separate file
Diffstat (limited to '')
-rw-r--r--bitwise.go21
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
+}