Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
[#16] Use better parameter names (#17)
Browse files Browse the repository at this point in the history
Closes #16
  • Loading branch information
rlespinasse committed Oct 11, 2017
1 parent 9022568 commit 01b43a0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
24 changes: 12 additions & 12 deletions bit_methods.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package gobits

// ContainsBit test if a bit (position b) is contains in a
func ContainsBit(a byte, b uint8) bool {
return ContainsBits(a, SetBit(0x00, b))
// ContainsBit test if a bit is contains in the data
func ContainsBit(data byte, bit uint8) bool {
return ContainsBits(data, SetBit(0x00, bit))
}

// SetBit change the bit (b) of a to 1
func SetBit(a byte, b uint8) byte {
return SetBits(a, 0x01<<b)
// SetBit change the bit of the data to 1
func SetBit(data byte, bit uint8) byte {
return SetBits(data, 0x01<<bit)
}

// UnsetBit change the bit (b) of a to 0
func UnsetBit(a byte, b uint8) byte {
return UnsetBits(a, 0x01<<b)
// UnsetBit change the bit of the data to 0
func UnsetBit(data byte, bit uint8) byte {
return UnsetBits(data, 0x01<<bit)
}

// GetBit get the bit from a byte
func GetBit(a byte, b uint8) byte {
return (a >> b & 0x01) << b
// GetBit get the bit value from the data
func GetBit(data byte, bit uint8) byte {
return (data >> bit & 0x01) << bit
}
18 changes: 9 additions & 9 deletions bits_methods.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package gobits

// ContainsBits test if b is contains in a
func ContainsBits(a, b byte) bool {
return a&b == b
func ContainsBits(data, bits byte) bool {
return data&bits == bits
}

// SetBits affect to a, the b bits
func SetBits(a, b byte) byte {
return a | b
func SetBits(data, bits byte) byte {
return data | bits
}

// UnsetBits unaffect to a, the b bits
func UnsetBits(a, b byte) byte {
return a &^ b
func UnsetBits(data, bits byte) byte {
return data &^ bits
}

// ExtractBits get a byte for subset of another byte
func ExtractBits(a byte, b, c uint8) byte {
var unusedBits = 7 + b - c
return a >> b << unusedBits >> unusedBits
func ExtractBits(data byte, lsb, msb uint8) byte {
var unusedBits = 7 + msb - lsb
return data >> msb << unusedBits >> unusedBits
}
2 changes: 1 addition & 1 deletion bits_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestUnsetBits(t *testing.T) {
}

func TestExtractBits(t *testing.T) {
var result = ExtractBits(0xDA, 3, 4)
var result = ExtractBits(0xDA, 4, 3)
if result != 0x03 {
t.Errorf("ExtractBits don't work: %08b", result)
}
Expand Down

0 comments on commit 01b43a0

Please sign in to comment.