conversions.binary_to_gray¶
Binary to Gray code conversion algorithm.
Reference: https://en.wikipedia.org/wiki/Gray_code
Attributes¶
Functions¶
|
Convert a binary number (as string) to its equivalent Gray code. |
Module Contents¶
- conversions.binary_to_gray.binary_to_gray(binary: str) str¶
Convert a binary number (as string) to its equivalent Gray code.
The Gray code is generated by XOR-ing each bit with the bit just before it.
- Args:
binary (str): A string representing a binary number (e.g., “10101010”).
- Returns:
str: The corresponding Gray code string.
- Example:
>>> binary_to_gray("10101010") '11111111'
>>> binary_to_gray("1101") '1011'
- conversions.binary_to_gray.binary_input¶