comnum.gray_code#
- comnum.gray_code(n_bits)#
The reflected binary Gray code of
n_bitsbits:g[i] = i ^ (i >> 1).- Parameters:
n_bits (int) – the number of bits.
- Returns:
the
2^n_bitscode words (int64).- Return type:
- Raises:
ValueError – for more than 24 bits (more than 16 777 216 code words).
Examples
>>> import comnum >>> comnum.gray_code(2).tolist() [0, 1, 3, 2]