GrayCode to Binary conversion
- Posted by euman at bellsouth.net Nov 15, 2002
- 403 views
This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C28CDE.06711DA0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The Euphoria Mailing List =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=20 Hello all, Would someone please tell me if my GrayCode to Binary routine is proper. The test Ive done so far seem to be accurate but I need further opinion. with trace trace(1) function Gray2Bin(atom Num) atom junk junk =3D floor(Num/2) return xor_bits(Num, junk) end function atom a,b,c,d,e,f,g a=3DGray2Bin(10) b=3DGray2Bin(11) c=3DGray2Bin(12) d=3DGray2Bin(13) e=3DGray2Bin(14) f=3DGray2Bin(15) g=3DGray2Bin(16) For those who might not know why Gray Code are used, here is a brief explan= ation: A Gray Code is a special type of binary code that doesnt use position weigh= ting, in other words, each position does not have a specific weight. Gray Code are setup s= o that as we progress from one number to the next, only one bit changes. Because only on= e bit changes at a time, the speed of transition for Gray Code is considerably faster tha= n BCD. =20 regards, Euman =3D=3D^= ^=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D rds at RapidEuphoria.com b2kUNk.= cmRzQFJh =3D=3D^= ^=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ------=_NextPart_000_0009_01C28CDE.06711DA0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; charset=3Diso-8859-1"= > <META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <PRE>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The Euphoria Mailing List =3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=20 </PRE> <DIV><FONT face=3DArial size=3D2>Hello all,</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Would someone please tell me if my GrayCod= e to=20 Binary routine is proper.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>The test Ive done so far seem to be accura= te =20 but I need further opinion.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>with trace<BR>trace(1)</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>function Gray2Bin(atom Num)<BR> atom= =20 junk<BR> junk =3D floor(Num/2)<BR> return xor_bits(Num, junk)<BR= >end=20 function</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>atom=20 a,b,c,d,e,f,g<BR>a=3DGray2Bin(10)<BR>b=3DGray2Bin(11)<BR>c=3DGray2Bin(12)<B= R>d=3DGray2Bin(13)<BR>e=3DGray2Bin(14)<BR>f=3DGray2Bin(15)<BR>g=3DGray2Bin(= 16)</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>For those who might not know why Gray Code= are=20 used, here is a brief explanation:</FONT></DIV> <DIV><FONT face=3DArial size=3D2>A Gray Code is a special type of binary co= de that=20 doesnt use position weighting, in other</FONT></DIV> <DIV><FONT face=3DArial size=3D2>words, each position does not have a speci= fic=20 weight. Gray Code are setup so that as we</FONT></DIV> <DIV><FONT face=3DArial size=3D2>progress from one number to the next, only= one bit=20 changes. Because only one bit changes</FONT></DIV> <DIV><FONT face=3DArial size=3D2>at a time, the speed of transition for Gra= y Code is=20 considerably faster than BCD.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>regards,</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Euman</FONT></DIV> <PRE>=3D=3D^= =3D=3D^=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D rds at RapidEuphoria.com b2kUNk.= cmRzQFJh">http://topica.com/u/?b1dd66.= b2kUNk.= cmRzQFJh</A> com/partner/tag02/register</A> =3D=3D^= =3D=3D^=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</PRE> </BODY></HTML> ------=_NextPart_000_0009_01C28CDE.06711DA0--