This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Closes #16
- Loading branch information
1 parent
9022568
commit 01b43a0
Showing
3 changed files
with
22 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters