package main
import (
"fmt"
"math"
)
// RoundToNextPowerOf2 returns the next power of 2 greater than or equal to n.
func RoundToNextPowerOf2(n uint) uint {
if n == 0 {
return 1
}
exp := math.Ceil(math.Log2(float64(n)))
return uint(math.Pow(2, exp))
}
func main() {
num := uint(21)
fmt.Printf("Next power of 2: %d\n", RoundToNextPowerOf2(num))
}
/*
run:
Next power of 2: 32
*/