mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-02-27 03:38:08 +08:00
17 lines
229 B
Go
17 lines
229 B
Go
package A
|
|
|
|
import "math/bits"
|
|
|
|
func reverseBits(n int) int {
|
|
res := 0
|
|
for i := 0; i < 32; i++ {
|
|
res = (res << 1) | (n & 1)
|
|
n >>= 1
|
|
}
|
|
return res
|
|
}
|
|
|
|
func reverseBits2(n int) int {
|
|
return int(bits.Reverse32((uint32(n))))
|
|
}
|