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
1
vote
1 answer

Encoding for strings (preferrably a value) such that closer values means more similar Strings?

I am looking for an encoding which can encode every string into a unique number such that -> Every two strings which are similar must have values close to each other. Every two values which are close to each other must represent similar…
Prakhar Ganesh
  • 117
  • 2
  • 8
1
vote
1 answer

Generate all combinations of a collection in o(1)

Combinations of a collection of int {1,2,3} is: {},{1},{2},{1,2},{3},{1,3},{2,3},{1,2,3} The common solution is to track the representative bit-mask of a index. From my example for numbers in 0-7: 000,001,010,011,100,101,110,111 This algorithm…
Dolev
  • 654
  • 11
  • 20
1
vote
4 answers

If given two hexadecimal numbers find if they can be consecutive in gray code

What is "consecutive in gray code" supposed to mean? I mean 10 and 11 are consecutive in decimal system but what is "consecutive in gray code" meaning? I only know gray code is a binary numeral system where two successive values differ in only one…
KKKK
  • 347
  • 7
  • 18
1
vote
1 answer

What is the most efficient way to generate subsets?

What I want to do is as follows: Input: n, for example n = 3 Output: {000, 001, 010, 011, 100, 101, 110, 111}, generate all the subsets and I don't care the order of the subsets I have implemented a algorithm: for (long i = 0, max = 1 << n; i < max;…
Mark Lin
  • 55
  • 4
1
vote
2 answers

grey codes using 2d arrays (C)

My assignment is to print out grey codes using recursion. A user puts in a bit value between 0-8, therefore the maximum amount of strings you can have is 256 (2^8). I've got the base case done but i don't know what I would do for the else…
San
  • 11
  • 4
1
vote
0 answers

How to use 64 bit in PHP

I wrote a function which will output a sequence of gray codes. For an input of N, showing the last N gray code numbers of N-bit. Now, this function is not giving the correct output if the input goes over 31. But I need this to work for at least 64.…
1
vote
2 answers

Binary To Gray Code and vice versa

So I want to write a program that takes a binary value as input and converts it into gray code and vice versa. Here's what I originally wrote: #include using namespace std; int main() { int Choice; bool…
user2299599
  • 19
  • 1
  • 6
1
vote
3 answers

Why gray code is an exclusive or of the bits in a binary code

I understood the purpose of gray codes in a clear way. EE Times: Gray Code Fundamentals But I am not able to conceptually understand why the gray code can be generated as below Gi = Bi+1 ⊕ Bi , i = n − 1, . . . , 0, where Bn is taken as 0. Could…
crackerplace
  • 5,305
  • 8
  • 34
  • 42
0
votes
2 answers

Assembly 8086: Converting 8-bit binary number to its Gray number equivalent?

Problem: Write a program to convert an 8-bit binary number entered from the keyboard to the equivalent Gray code binary number, using the following the algorithm: [broken image: http://www.harborlandings.com/images/grayAlgm.jpg] I'm learning…
Jeremiah Burley
  • 281
  • 2
  • 4
  • 8
0
votes
1 answer

Generate a powerset with the help of a binary representation

I know that "a powerset is simply any number between 0 and 2^N-1 where N is number of set members and one in binary presentation denotes presence of corresponding member". (Hynek -Pichi- Vychodil) I would like to generate a powerset using this…
skanatek
  • 5,133
  • 3
  • 47
  • 75
0
votes
2 answers

How to program a MIP solver to find balanced Gray code for mixed radices?

The permutations of a mixed radix number can be ordered to achieve Grayness (in the sense of Gray code) with optimal balance and span length. Each of these constraints will be explained in turn. In my examples, I use a mixed radix number consisting…
0
votes
0 answers

how convert opencv c++ graycode->decode() function to cv2 python

In my project, I want to convert a C++ code from the opencv library into a Python code. My C++ code reference is below. https://docs.opencv.org/4.x/dc/da9/tutorial_decode_graycode_pattern.html In the C++ section, I came across a function that is as…
0
votes
0 answers

Stereo camera structured light disparity problem

i want to build 3d scanner with stereo camera and LED Projector. I calibrated the stereo camera and created the mechanical system. I project gray code and capture them with two camera. I decoded the images and take correspondence image. But i can't…
0
votes
1 answer

What is the intuition behind gray code generation?

uint BinaryToGray(uint num) { return num ^ (num >> 1); // The operator >> is shift right. The operator ^ is exclusive or. } Why does this work?
0
votes
1 answer

How to print n-bit gray codes specifically using backtracking?

I codded a program to print n-bit binary gray codes. But I'm not sure if it is a backtracking program. If it is not a backtracking program, what is something I can do to use it in this code. I want to print the binary codes themselves, not their…
Hanzo
  • 1