blob: 689e667ce7125de5c606d6b38c82bfd9347dbe95 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
// SPDX-License-Identifier: BSD-2-Clause
// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
package main
// validateBitZeros checks if the first n bits of a byte slice are all zeros.
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
}
|