1 Star 0 Fork 40

peng2289/go808

forked from coco/go808 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bit.go 866 Bytes
一键复制 编辑 原始数据 按行查看 历史
coco 提交于 2020-04-02 18:23 +08:00 . initial commit
package protocol
func GetBitByte(value byte, offset int) bool {
if offset >= 8 {
return false
}
return value&(1<<offset) > 0
}
func SetBitByte(value *byte, offset int, set bool) {
if offset >= 32 {
return
}
if set {
*value |= 1 << offset
} else {
*value &= ^(1 << offset)
}
}
func GetBitUint16(value uint16, offset int) bool {
if offset >= 16 {
return false
}
return value&(1<<offset) > 0
}
func SetBitUint16(value *uint16, offset int, set bool) {
if offset >= 32 {
return
}
if set {
*value |= 1 << offset
} else {
*value &= ^(1 << offset)
}
}
func GetBitUint32(value uint32, offset int) bool {
if offset >= 32 {
return false
}
return value&(1<<offset) > 0
}
func SetBitUint32(value *uint32, offset int, set bool) {
if offset >= 32 {
return
}
if set {
*value |= 1 << offset
} else {
*value &= ^(1 << offset)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/oco/go808.git
git@gitee.com:oco/go808.git
oco
go808
go808
32b1471f79b9

搜索帮助