- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Convert Binary to Gray Code
When it is required to convert binary code to gray code, a method is defined that performs the ‘xor’ operation.
Below is the demonstration of the same −
def binary_to_gray_op(n): n = int(n, 2) n ^= (n >> 1) return bin(n)[2:] gray_val = input('Enter the binary number: ') binary_val = binary_to_gray_op(gray_val) print('Gray codeword is :', binary_val)
Enter the binary number: 101100110 Gray codeword is : 111010101
A method named ‘binary_to_gray_op’ is defined, that takes the binary number as its parameter.
It performs the ‘xor’ operation.
It returns the converted output.
The input of binary number is taken from the user.
The function is called, and this value is passed as a parameter to it.
The converted output is displayed on the console.
- Python Program to Convert Gray Code to Binary
- C++ Program to convert the Binary number to Gray code using recursion
- 8085 program to convert gray to binary
- 8085 program to convert binary numbers to gray
- Program to convert gray code for a given number in python
- Binary to Gray code using recursion in C program
- Conversion of Binary to Gray Code\n
- Conversion of Gray Code to Binary\n
- 8086 program to convert binary to Grey code
- 8085 code to convert binary number to ASCII code
- Python program to convert floating to binary
- Python program to convert decimal to binary number
- Convert decimal to binary number in Python program
- Gray Code in C++
- Python Program to Generate Gray Codes using Recursion