Why does `0usize`.reverse_bits() produce `0`?

Shouldn't it produce 0xffffffffffffffff?

:man_facepalming:
It's reversing the direction of bits, not inverting bits...

3 Likes

It's not flipping the bits but reversing it, i.e. from LSB to MSB. I think you mean flip bits?

2 Likes

Use ! if you actually want to flip the bits, e.g. !0.

1 Like

Reverse bits, not bytes

Reverse bits swaps the bit order of the value, end to end. The OP seems to want "invert bits", not "reverse bits".

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.