Unbewohnte
3 years ago
4 changed files with 61 additions and 21 deletions
@ -0,0 +1,6 @@ |
|||||||
|
package util |
||||||
|
|
||||||
|
// Tells if bit is set in given byte
|
||||||
|
func IsSet(n byte, bitN int) bool { |
||||||
|
return n&byte(1<<bitN-1) != 0 |
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package util |
||||||
|
|
||||||
|
import "testing" |
||||||
|
|
||||||
|
func TestIsSet(t *testing.T) { |
||||||
|
testBytes := []byte{1 << 0, 1 << 1, 1 << 2, 1 << 3} |
||||||
|
|
||||||
|
for index, testByte := range testBytes { |
||||||
|
if !IsSet(testByte, index+1) { |
||||||
|
t.Errorf("IsSet failed: expected %dth bit of %d to be %v; got %v", |
||||||
|
index+1, testByte, true, IsSet(testByte, index+1)) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue