How to make an integer with N bits set without overflow

pub fn setbits(x: u8) -> u32 {
    u32::MAX >> (32 - x)
}
2 Likes