Skip to main content

gray

Function gray 

Source
pub fn gray(i: usize) -> usize
Expand description

The binary reflected Gray code $g(i) = i \oplus \lfloor i/2 \rfloor$.

§Examples

use comnum_math::gray;
assert_eq!((0..8).map(gray).collect::<Vec<_>>(), [0, 1, 3, 2, 6, 7, 5, 4]);