Probably by laziness ;-). I read the rust doc and I understood nothing. The links that you provided was clearer.
This operator is quite useful for bit calculation... I can even easily invert the operation you gave:
fn bit_split(to_split: u128, bit: u32, stack: &mut Vec<u128>) {
let mut max_size_bit: u128 = 0;
for i in 0..bit {
max_size_bit = max_size_bit | 1 << i;
}
stack.push(to_split & max_size_bit);
let next_to_split = to_split >> bit;
if to_split >> bit != 0 {
bit_split(next_to_split, bit, stack)
}
}
For example bit_split(8, 1, &mut stack) give a stack of 8 splited in 1 bit ( [0, 0, 0, 1])
I have 1 more question linked:
How performances are impacted when you store a u128 in a u32 stack? what the idiotic way to choose the size in rust? using "usize" and "isize"?
I presume you mean idiomatic? There are unlimited idiotic ways to do things in any programming language.
Use usize for counting things that are in memory. Otherwise use the right size for whatever you are doing. Don't use u32 to track the U.S. national debt, but it's fine for counting the eggs in most recipes.