Questions tagged [gray-code]

Anything related to Gray code, also known as reflected binary code, i.e. a n-bit binary code where any one of the 2^n binary code words differs from the next in just one bit position.

Anything related to Gray code, also known as reflected binary code, i.e. a n-bit binary code where any one of the 2n binary code words differs from the next in just one bit position.

Gray codes were invented in 1947 by Frank Gray and are used to solve a variety of problems (e.g. Tower of Hanoi) and to ease error correction in some communication systems.

See Wikipedia page on Gray code.

90 questions
2
votes
4 answers

Working of a Gray Code

I am trying to understand the working of gray code. If we give any non-negative integer n (where n is the number of bits) then we need to print its gray code sequence. Below are some examples 2-bit Grey Code sequence Input = 2 bits 00 - 0 01 - 1 11…
Coding Bad
  • 252
  • 1
  • 4
  • 12
2
votes
1 answer

Use of __builtin_expected for bounds check

I have this function which, given a Gray code, returns the next Gray code. You can find a more complete explanation about how it works here. The thing is that I wanted to make this increment function modular so that incrementing the Gray code…
Morwenn
  • 21,684
  • 12
  • 93
  • 152
2
votes
1 answer

Gray code for all k element subset of {1,...,n}

I am seeking for an algorithm which iterates through all k element subsets of an n element set. I do not want to generate all those subset explicitly. There is an easy algorithm to do this, namely sorting the corresponding bit vectors…
mueldgog
  • 383
  • 1
  • 7
2
votes
1 answer

Non-recursive Grey code algorithm understanding

This is task from algorithms book. The thing is that I completely don't know where to start! Trace the following non-recursive algorithm to generate the binary reflexive Gray code of order 4. Start with the n-bit string of all 0’s. For i = 1, 2,…
Mike
  • 842
  • 1
  • 9
  • 31
2
votes
1 answer

Magic number in reflected gray code to binary conversion

I wrote a generic function to convert a binary reflected gray code to standard binary. I used an algorithm I found on this page. Here is the aforementioned algorithm: unsigned short grayToBinary(unsigned short num) { unsigned short temp =…
Morwenn
  • 21,684
  • 12
  • 93
  • 152
2
votes
3 answers

The neighbors in Gray code

Is there any algorithm that I can use to find the neighbors in Gray code? For small numbers is just fine to write the entire table, but if I have a number like 010 110 is a bit to much to write the entire grey code table with 6 numbers.
redhat01
  • 135
  • 4
  • 14
1
vote
1 answer

what is a GR image?

My teacher has assigned me to work combine RGB channels and create a GR image, whose results are like a negative image as shown here: I have tried the following…
1
vote
1 answer

Optimal bit twiddling for the One's complement absolute value operation on modern x86 processors

The fastest way to compute the absolute value of a twos complement number is a common enough operation that optimized implementations are widely available. So let's consider another case. What if we want to get the absolute value of a one's…
saolof
  • 1,097
  • 1
  • 15
  • 12
1
vote
1 answer

clock domain crossing of a mutli bit signal

I have to use a multibit counter signal in another clock domain from the one that is generated. If there is no relation between the 2 clocks, is it safe to use gray code and classic 2 sync FFs and just read the coded value after that (just like it…
1
vote
1 answer

Increasing Efficiency of binary -> gray code for 8086

I am a beginner in assembly and This is a code that I designed to convert from binary and to gray, and prints the resulting bit-pattern in hex. mov al, a mov bl, al shr bl, 1 xor al, bl …
user15824199
1
vote
3 answers

How to get Gray-Code from Decimal number

Possible Duplicate: Gray code in .NET I want to get Gray code of a number from its Decimal equivalent. Example: Dec Gray Binary 0 000 000 1 001 001 2 011 010 3 010 011 4 110 100 5 111 101 6 101 110 7 …
Javed Akram
  • 15,024
  • 26
  • 81
  • 118
1
vote
7 answers

Gray Code to Binary Code Conversion

So I'm trying to write a function that will convert a 7-bit Gray code to the corresponding 7-bit Binary Code. Here's how to convert - Gray Value bits ---- MS bit > (G6) G5 G4 G3 G2 G1 G0 * Binary Value bits -- MS bit > (B6) B5 B4 B3 B2 B1 B0 * B6 =…
S_Wheelan
  • 267
  • 2
  • 5
  • 8
1
vote
1 answer

Generate integers with even hamming weight (popcount) c++

I want to effectively (by using bit hacks) generate all integers up a given number, k, such that they have an even hamming weight without explicitly calculating their hamming weights. It is not important to me whether that is done in ascending or…
1
vote
2 answers

Converting a Grayscale image to its original color format using Python

Hi I am currently working on trying to convert a gray scale image to its original color format using Open CV in python. import cv2 img = cv2.imread('bw.jpg') img = cv2.cvtColor(img,…
AshBookReader
  • 23
  • 1
  • 5
1
vote
2 answers

Choose some numbers coding in Gray Code

I have to write a programm that shows some numbers coding in Gray Code. I already found an algorithm written in C++ in this page (…
Red One
  • 133
  • 7