answersLogoWhite

0


Best Answer

Gray code, named after Frank Gray, a Bell Labs researcher who originally called it "reflected binary code", is used to help correct errors in digital communications. It was developed as a response to preventing desynchronized switching actions, requiring only one switch be flipped to increment or decrement a binary value represented by a hardware-based switch array.

The simplest method, without using a whole lot of CPU or brain power, is to create an array of Gray code values that correspond to their binary representation. For example, a 2-bit Gray code array would consist of the following values:

int gray2bit[]={0, 1, 3, 2};

A 3-bit Gray code array would be declared and initialized as follows:

int gray3bit[]={0, 1, 3, 2, 6, 7, 5, 4};

To find the Gray code for a particular value, simply reference that offset in the desired array:

int n=gray2bit[2]; /* results in 3 */

int m=gray3bit[6]; /* results in 5 */

See the related links for more information on Gray codes as well as sample source code that will assist you further.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program to convert binary code to gray code using c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


Write a C program that takes a binary file as input and finds error check using different mechanisms?

write a c program that takes a binary file as input and finds error check using different mechanisms.


Write a Program to convert decimal number into hexadecimal no without using function and string?

This is not a question.


Write algorithms and draw a corresponding flow chart to convert a decimal number to binary equiavalent?

Write algorithms and draw a corresponding flow chart to convert a decimal number to binary equivalent?


How do you write a C program to convert a binary value to its octal equivalent?

To convert from binary to octal, bitwise AND the binary value with 0x8 (00000111 in binary) and push the value onto a stack. Right-shift (>>) the binary value by 3 bits and repeat until the binary value is zero. Pop the stack to build the left-to-right digits of the octal value. Using 10110100 as an example: 10110100 & 00000111 = 00000100 10110100 >> 3 = 00010110 00010110 & 00000111 = 00000110 00010110 >> 3 = 00000010 00000010 & 00000111 = 00000010 00000010 >> 3 = 00000000 Popping the values in order reveals 00000010, 00000110 and 00000100 (decimal 2, 6 and 4 respectively). Thus 10110100 binary is 0264 octal.

Related questions

How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


Write a C program that takes a binary file as input and finds error check using different mechanisms?

write a c program that takes a binary file as input and finds error check using different mechanisms.


Write a c program to convert binary number to decimal number?

How is this a question? Sounds like you should do more of your homework offline.


Write a program that takes a binary file as input and finds error check using different mechanism?

networking


Write a Program to convert decimal number into hexadecimal no without using function and string?

This is not a question.


Write a program to convert stack into queue using c language?

In order to write a program to convert stack into queue using c language you must be able to identify the proper program. Having a special certification in programing will be beneficial as well to make sure you recognize the proper queues for the programs.


Write algorithms and draw a corresponding flow chart to convert a decimal number to binary equiavalent?

Write algorithms and draw a corresponding flow chart to convert a decimal number to binary equivalent?


Write a program to convert a 2 digit BCD number into hexadecimal number?

Write a program to convert a 2-digit BCD number into hexadecimal


Write a program of binary heap in c or c language?

to implement operations on binary heap in c


How do you convert Binary-to-Decimal and Decimal-to-Binary?

You can use a table to convert binary to decimal & back:MSBBinary DigitLSB2827262524232221202561286432168421Figure out the greatest power that will fit into the number you want to convert to binary. Move to the next lower power of two. If you can fit into the next lower number write down a "1", if it can't put down "0". Put together the binary answer.


2 Write a program to convert a 2-digit BCD number into hexadecimal?

WRITE A PROGRAM TO CONVERT A 2-DIGIT bcd NUMBER INTO HEXADECIMAL


How can you write a program to convert binary code to gray code using 8085 microprocessor?

It can be implemented very easily .... Suppose the Binary word is X7X6X5.... X0 then the corresponding Gray code is G7G6G5....G0 where G7=X7 G6=X7 XOR X6 G5=X6 XOR X5 ..... G0=X1 XOR X0 Now implement the above algorithm