Skip to main content

log_2_ceil

Function log_2_ceil 

Source
pub fn log_2_ceil(val: u32) -> u32
Expand description

Returns the number of bits needed to represent the given number.

Inspired by https://graphics.stanford.edu/~seander/bithacks.html

use lance_core::utils::bit::log_2_ceil;

assert_eq!(log_2_ceil(1), 1);
assert_eq!(log_2_ceil(2), 2);
assert_eq!(log_2_ceil(255), 8);
assert_eq!(log_2_ceil(256), 9);