4 Star 25 Fork 17

编程语言算法集 / Go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
reversebits.go 715 Bytes
一键复制 编辑 原始数据 按行查看 历史
Ilya Sokolov 提交于 2021-10-06 09:29 . feat: reverse bits (#371)
// reversebits.go
// description: Reverse bits
// details:
// Reverse the bits of an integer number
// author(s) [red_byte](https://github.com/i-redbyte)
// see reversebits_test.go
package binary
// ReverseBits This function initialized the result by 0 (all bits 0) and process the given number starting
// from its least significant bit. If the current bit is 1, set the corresponding most significant bit in the result
// and finally move on to the next bit in the input number.
// Repeat this till all its bits are processed.
func ReverseBits(number uint) uint {
result := uint(0)
intSize := 31
for number != 0 {
result += (number & 1) << intSize
number = number >> 1
intSize -= 1
}
return result
}
Go
1
https://gitee.com/TheAlgorithms/Go.git
git@gitee.com:TheAlgorithms/Go.git
TheAlgorithms
Go
Go
master

搜索帮助