Expand description

Miscellaneous bit operations for any [Integer].

Examples

extern crate xor_distance_exercise;

use xor_distance_exercise::bitops::{is_flag, is_bit_set, is_flag_set, set_bit, set_flag};

let x = 0b1000_0000_1001_1010;
let flag = 0b1000_0000;

assert!(is_flag(flag));
assert!(is_bit_set(flag, 7));
assert!(is_flag_set(x, flag));

let mut y = 0b1000_0000_0001_1010;

set_flag(&mut y, flag);
assert_eq!(0b1000_0000_1001_1010, y);

set_bit(&mut y, 0);
assert_eq!(0b1000_0000_1001_1011, y);

Functions

Returns whether the bit on specified bit index is set to “1”.
Returns whether this number only has one bit set.
Returns whether the given flag is set.
Set bit to “1” for specified bit index. Indexed from zero.
Set flag.