LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Decimal to Gray Code

Hi,
 
This might be a fairly basic question:
 
I've a piece of data in decimal format. How can I translate it in Gray Code using LabVIEW?
 
Thanks,
Manson
0 Kudos
Message 1 of 17
(5,283 Views)
Just a bit of boolean array manipulation gets you there. See the attached VI.

This is saved in 7.1,  so let me know if you need it in an earlier version or have any problems or questions.

Ed


Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 2 of 17
(5,275 Views)
Manson,

My understanding of a Gray code is that it is a counting sequence where only one bit changes at each increment/decrement step. For such a process any integer value, regardless of format, is a valid value in a Gray code, so the concept of translation does not seem to make sense to me.

Can you explain in more detail what you are trying to do?

Lynn
0 Kudos
Message 3 of 17
(5,276 Views)

Thank Ed. That helps!

Just out of curiosity. How do you create the error in / out cluster you used in your attached VI? I tried to manually put in the parameters in a cluster, but the error warning function (right click error) didn't come out.

Thanks,

Manson

0 Kudos
Message 4 of 17
(5,263 Views)
The error clusters can be found in the cluster palette of the CONTROLS palette (the one you get when you right click the FP).

___________________
Try to take over the world!
0 Kudos
Message 5 of 17
(5,254 Views)
Gray code was written such that any increment or decrement of the integer value would result in only one bit being changed in the binary representation of the integers.  If incrementing from integer values 1 to 2, the binary representations are 0000 0001 and 0000 0010.  You can see that bits 0 and 1 have both changed.  The Grey code representations for 1 and 2 are 0000 0001 and 0000 0011.  Here you can see that only bit 1 has changed.  Bit 0 has remained that same.  Remember, integer values 1 and 2 are bytes, not bits.  Grey code was invented to have only one BIT change at a time.
- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 17
(5,241 Views)

Hi,

The Gray Code I generated is from left to right (e.g. 20 = 01111, but the correct format should be 11110). How can I flip the left digits to the right and vice versa?

Thanks,

Manson

0 Kudos
Message 7 of 17
(5,233 Views)
Use reverse 1D Array function found in Array palette.  See attached vi.
- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 17
(5,225 Views)
Well, the attachement didn't go through.  Try again...
- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 17
(5,223 Views)
 In other word, how can I rotate the image (see attached .jpg file) 90 degrees clockwise so that it reads 11110 from left to right?
 
Thanks,
Manson
0 Kudos
Message 10 of 17
(5,224 Views)