github.com/jxskiss/gopkg@v0.17.3/internal/math.go (about)

     1  package internal
     2  
     3  func NextPowerOfTwo(x int) int {
     4  	if x <= 1 {
     5  		return 1
     6  	}
     7  
     8  	x--
     9  	x |= x >> 1
    10  	x |= x >> 2
    11  	x |= x >> 4
    12  	x |= x >> 8
    13  	x |= x >> 16
    14  	x |= x >> 32
    15  
    16  	return x + 1
    17  }