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

Netlogo: Convert Gray Code to Binary

I am using genetic algorithms to determine survival in my Netlogo model, and the ultimate output of the GA is a decimal number between 0 and 1, inclusive. For crossover / mutation purposes, I need to work with gray code rather than binary numbers. …
0
votes
1 answer

3-bit finite state machine in VHDL

entity project4 is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; x : in STD_LOGIC_VECTOR (1 downto 0); myoutputs : out STD_LOGIC_VECTOR (2 downto 0)); end project4; architecture Behavioral of project4…
Jack
  • 121
  • 4
0
votes
2 answers

How to tell if two 8-bit chars are gray codes in c++?

The problem is to tell if two 8-bit chars are gray codes(differ only in 1 bit) in C++? I found an elegant C++ solution: bool isGray(char a, char b) { int m = a ^ b; return m != 0 && (m & (m - 1) & 0xff) == 0; } I was confused that what does…
user3692521
  • 2,563
  • 5
  • 27
  • 33
0
votes
2 answers

Convert decimal to gray code in java

Had a question come up recently which was: write the algorithm to convert a decimal number to an n-bit gray code. So for example: Using 1-bit (simplest): 0 -> 0 1 -> 1 Using 2-bit 0 -> 00 1 -> 01 2 -> 11 3 -> 10 Using 3-bit 0 -> 000 1 -> 001 2 ->…
Nabeel Saad
  • 152
  • 2
  • 12
0
votes
1 answer

Is there any simple way to add a prefix to each element of an array in C?

I'm solving gray code problem. I made my logic using recursive call. Everything look ok but I have no idea how to prefix '0' or '1' to each element of an array. eg) prefix 0 : { 00, 01, 11, 10 } -> { 000, 001, 011, 010 } or prefix 1 : { 00,…
Vincent Gigandet
  • 918
  • 10
  • 21
0
votes
2 answers

Gray rank algorithm implementation in python

How can I implement the following algorithm in python: (source) def getGraycodeRank(n, t): r = 0#range b = 0 for i in reversed(range(0, n)): if n - i IS IN t: #how to check it? b = 1-b if b == 1: …
Michal_Szulc
  • 4,097
  • 6
  • 32
  • 59
0
votes
2 answers

Convert Gray Code to Decimal in R

I have a set of 0's and 1's represented as a list initially created with sample(c(0,1), n, replace=TRUE), where n is the length of my binary number. I'm currently using a BCD converter to convert my binary number to a decimal number, this is seen…
Fozefy
  • 665
  • 2
  • 7
  • 23
0
votes
1 answer

Generic Binary-Gray, gray-binary converter, logic error

It shows me an error: ERROR:Xst:787 - "E:/tumama/tytyty.vhd" line 54: Index value <4> is not in Range of array . Its a "generic" code, my embedded signal A has the 5 bits of n I only want to use 4 bits to convert in a case. So i have 4 bits in…
Mac
  • 111
  • 7
  • 14
0
votes
2 answers

Fill matrix with binary numbers, regular and gray coded

I have a matrix that holds 1:s or 0:s, creating binary numbers. Its width is n. For n = 2 and n = 3 it would look like: 00 000 01 001 10 010 11 011 100 101 110 111 and so on. Right now I'm using the following code to produce…
Goatcat
  • 1,133
  • 2
  • 14
  • 31
0
votes
1 answer

VHDL gray code counter

I'm trying to implement a gray code counter using a shift register and a 4-1 MUX. Does anyone have an idea what logic to use?! Thanks
Melodie Gauthier
  • 685
  • 3
  • 12
  • 35
0
votes
2 answers

Strange Gray Code - Efficient Decoding

I am trying to figure out an efficient way to go from a strange Gray code to either Binary Reflected Gray Code or to normal binary. The pattern…
mike29892
  • 263
  • 3
  • 13
-1
votes
1 answer

Encoding a value in gray code with floating point with negatives

My objective here is to be able to convert any number between -4.0 and 4.0 into a 5 bit binary string using gray code. I also need to be able to convert back to decimal. Thanks for any help you can provide. If it helps, the bigger picture here is…
zaedric
  • 45
  • 1
  • 7
-1
votes
1 answer

generate all subsets of set given by binary representation of integer in c++

In c++ I am searching for an efficient algorithm to generate all integers such that their binary representation is a subset of a set which is given by the binary representation of integer N. By efficient I mean that I don't want to for-loop through…
-1
votes
1 answer

generate binary one bit change between all members

ı have a question. ı want to generate binary list .but between members of the list will be only one bit change. oneBitAll :: Integral a => a -> [[String]] for n=2 Output: ["00","01","11","10"] ve ["00","10","11","01"] n=3 oneBitAll 3 …
rooney
  • 3
  • 4
-4
votes
2 answers

Can anybody explain me print statement in this code?

I found this code on internet but I am not able to understand how the print statement is working. I have already tried to see many answers but none answers it perfectly. def main(): n=int(raw_input()) for i in range(0, 1<
1 2 3 4 5
6