From 71559a48afc860d124b4ddfeb8df752b22a25053 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 23 Mar 2025 12:01:36 +0800 Subject: Separate validateBitZeros into a separate file --- bitwise.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 bitwise.go (limited to 'bitwise.go') 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 +} -- cgit v1.2.3