pub fn bits_needed(max_val: u32) -> u8
Compute the number of bits needed to represent the maximum value