Skip to content

Instantly share code, notes, and snippets.

View nojima's full-sized avatar
o_O

Yusuke Nojima nojima

o_O
View GitHub Profile
@nojima
nojima / bit_ceil.go
Last active August 16, 2024 07:39
Efficient way to calculate the minimum power of 2 that is greater than or equal to the given integer
package main
import (
"fmt"
"math/bits"
)
// BitCeil returns the minimum power of 2 that is greater than or equal to x.
// It returns 1 when x is 0.
func BitCeil(x uint) uint {