Function alcibiades::bitsets::below_lsb_including
[−]
[src]
pub fn below_lsb_including(x: Bitboard) -> Bitboard
Returns a mask with all bits below and including the LSB set to
1
.
The way to calculate this is: below_lsb_including = x ^ (x - 1);
.
If x
is 0
this function returns 0xffffffffffffffff
.
Examples:
assert_eq!(below_lsb_including(0b10100), 0b111); assert_eq!(below_lsb_including(0), !0);
x ^ (x - 1) = below_lsb_including(x)
. . . . . . . . . . . . . . . . . . . . . . . .
. . 1 . 1 . . . . . 1 . 1 . . . . . . . . . . .
. 1 . . . 1 . . . 1 . . . 1 . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
. 1 . . . 1 . . ^ . 1 . . . 1 . . = . . . . . . . .
. . 1 . 1 . . . 1 1 . . 1 . . . 1 1 1 . . . . .
. . . . . . . . 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
. . . . . . . . 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1