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
0
votes
1 answer

How to generate a sequence of indexes of a nested loop that has cache locality?

Imagine you have two arrays and you want to iterate a nested loop of them, such as the following: #include int main(void) { int sizes[5] = {4, 4}; for (int i = 0 ; i < sizes[0]; i++) { for (int j = 0 ; j < sizes[1]; j++) { …
Samuel Squire
  • 127
  • 3
  • 13
0
votes
1 answer

Opencv Decode Gray code pattern tutorial 3D scanner Problems

I used a ready-made tutorial code from the opencv library in C ++, the link is as follows: https://docs.opencv.org/3.4/dc/da9/tutorial_decode_graycode_pattern.html This is the title of this code (Decode Gray code pattern tutorial) The job of this…
0
votes
3 answers

Python GrayCode saved as string directly to decimal

Im working for a python project and i wonder if the following is possible: Currently I have a graycode stored as an string i.e: "1000" and I want to convert it to is integer (decimal, base10) value --> 15
DolGps
  • 3
  • 2
0
votes
1 answer

Hi am confused about output when we give input as 4 while it works for 3

My Output : [0,1,3,2,6,7,5,4,13,12,14,15,10,11,9,8] Expected O/P: [0,1,3,2,6,7,5,4,13,12,14,15,10,11,9,8] n = 4 while debugging it's doing the right index calculations but it's still adding 13 instead of 12 first. Problem: An n-bit gray code…
0
votes
2 answers

Convert Gray Code to Binary and vice versa

I wrote this function but can't find out what's wrong can someone help me please. It gives the output as 513. I have added the function for both binary and gray please help Me! Thanks :) function xor_c (a,b){ return (a==b)?'0':'1'; } function…
user15392801
0
votes
1 answer

Gray code pattern looks like binary pattern. Is this correct?

I have this following gray code pattern but it looks like binary pattern to me. Please let me know if this is correct or something has to be changed? n = ceil(log2(py)); T = length(n) ; gray_pattrn = zeros(2^n,1) ; gray_pattrn(2) = 1; T = 2; for …
dazemood
  • 23
  • 5
0
votes
1 answer

Converting from binary to gray works in assembly, but not vice versa

I am trying to build a program for PicoBlaze which will translate from Gray code to binary and vice versa. Here is what I've made thus far: address 0 start: ;Infinite loop... ;Converting from binary to gray... constant binary_input,0 constant…
FlatAssembler
  • 667
  • 7
  • 30
0
votes
1 answer

Cartesian product in Gray code order : including affected set in this order?

Having an excellent solution to: Cartesian product in Gray code order with itertools?, is there a way to add something simple to this solution to also report the set (its index) that underwent the change in going from one element to the next of the…
0
votes
2 answers

low-memory pseudo-random shuffle for fixed arbitrary length array

Context: I'm writing an external SRAM tester for a microcontroller-based embedded system. No security, no cryptography involved. For reproducible access to "as-non-consecutive-as-possible" memory locations, I'm looking for an implementation of y =…
Xpector
  • 639
  • 1
  • 5
  • 17
0
votes
0 answers

Binary_to_Gray code conversion using Python

I wrote a program to convert binary code to Gray code using only string operation. I want to check the feasibility of my code and also whether it's the right or wrong approach. def binary_to_gray(x): x = str(x) gray = x[0] for i in…
0
votes
1 answer

Convert a character array of binary numbers into a counter of Gray Code in C++

is there any way to convert a char array of binary number into Gray Code. For example, I have the following code: int j; char binaryNum[10], *pointer; /* From Hex convert to decimal */ j = strtol( str, &pointer, 16); /* From Decimal convert to…
bijlikamasla
  • 371
  • 3
  • 6
  • 11
0
votes
1 answer

All combinations of n binary values in an order that just one component changes compared to the prior combination

Below is a vector with all the possible combinations of 2 binary values: [(1,1),(1,0),(0,1),(0,0)] Now, the question is how I can generate a sequence of the same combinations of 2 binary values that each of them has only one component changed…
Ark
  • 457
  • 1
  • 8
  • 18
0
votes
2 answers

VHDL Data Flow description of Gray Code Incrementer

I am trying to write the VHDL code for a Gray Code incrementer using the Data Flow description style. I do not understand how to translate the for loop I used in the behavioral description into the Data Flow description. Any suggestion? This is my…
matteof93
  • 43
  • 9
0
votes
1 answer

9's complement of a 4-bit binary number

I don't understand how to calculate the 9's complement of a binary number. I can apply it to decimal ones, example 15 = (9-1)(9-5) ) 84 then I thought to proceed with a binary -> decimal -> 9's complement -> binary conversion but I guess it's not…
user3595871
  • 1
  • 1
  • 1
  • 3
0
votes
2 answers

Deriving nth Gray code from the (n-1)th Gray Code

Is there a way to derive the 4-bit nth Gray code using the (n-1)th Gray code by using bit operations on the (n-1)th Gray Code? For example the 4th Gray code is 0010. Now I want to get the 5th Gray Code, 0110, by doing bit operations on 0010.
samurdhilbk
  • 419
  • 1
  • 5
  • 16