mybitsGo
UNIT 15 test scopes
*Modelled on math/bits.*
math/bits provides most of its functions in several widths. You write the 32-bit version only, exactly as the standard one.
func OnesCount32(x uint32) int func Len32(x uint32) int func RotateLeft32(x uint32, k int) uint32 func Reverse32(x uint32) uint32 func ReverseBytes32(x uint32) uint32
All standard:
| Yours | Standard |
OnesCount32 | math/bits.OnesCount32 |
Len32 | math/bits.Len32 |
RotateLeft32 | math/bits.RotateLeft32 |
Reverse32 | math/bits.Reverse32 |
ReverseBytes32 | math/bits.ReverseBytes32 |
Things to find out in your tests:
- x & (x-1) clears the lowest set bit of x. Why? Write OnesCount32 again with it.
- What does x &^ y do? How does it differ from x & ^y?
- Compare the 8, 16, 32 and 64-bit versions in the real package. What changes between them?
OnesCount32 GoDoc
OnesCount32 counts the bits set to 1 in x. Zero has no set bits.
math/bits.OnesCount32 ↗package mybits supplied automatically
Saved locallyUTF-8 · tabs
Test results
Ready when you are
8 automatic test groups for OnesCount32.
Assertions stay hidden until you choose to see them.