toggle_bit

Function toggle_bit 

Source
pub const fn toggle_bit(val: u16, bit: u16) -> u16
Expand description

Toggles (flips) the given bit.

The bit position starts at 0.

§Parameters

  • base: Base value to alter.
  • bit: Bit to toggle, starting at position 0.

§Example

use bit_ops::bitops_u16::toggle_bit;

assert_eq!(toggle_bit(0, 0), 1);
assert_eq!(toggle_bit(0, 1), 2);
assert_eq!(toggle_bit(0, 2), 4);
assert_eq!(toggle_bit(0, 7), 128);

§Panics

This function panics for bit positions that are outside the range of the underlying type.