1. GrayCode to Binary conversion

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>&nbsp;</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&nbsp;=20
but I need further opinion.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>with trace<BR>trace(1)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>function Gray2Bin(atom Num)<BR>&nbsp;atom=
=20
junk<BR>&nbsp; junk =3D floor(Num/2)<BR>&nbsp;return xor_bits(Num, junk)<BR=
>end=20
function</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</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>&nbsp;</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--

new topic     » topic index » view message » categorize

2. Re: GrayCode to Binary conversion

On 15 Nov 2002, at 19:34, euman at bellsouth.net wrote:

<snip>

> For those who might not know why Gray Code are used, here is a brief
> explanation: A Gray Code is a special type of binary code that doesnt use
> position weighting, in other words, each position does not have a specific
> weight. Gray Code are setup so that as we progress from one number to the
> next,
> only one bit changes. Because only one bit changes at a time, the speed of
> transition for Gray Code is considerably faster than BCD.

Mechanically, for position encoders, it's faster, because you don't need to 
care about bit-change alignment, or when to clock the input into the digital 
equipment. That's why the gray code was invented. Bit phase jitter is a major 
pain to interfacing to the real world on mechanical systems, what with 
oscillation in shafts and vibration in supporting frames, and just general 
physical slop in the switches and encoders. It was a problem in tape drives, 
paper tape, and card readers. It is in AD and DA convertors too, actually, but 
that's solved with throwing more electronics at the problem. Or in one case i 
had to solve, by making all the lines to the 200Mhz ecl d/a chip the same 
length, pcb layout people are not engineers.

Kat

new topic     » goto parent     » topic index » view message » categorize

3. Re: GrayCode to Binary conversion

On Fri, 15 Nov 2002 19:34:33 -0500, euman at bellsouth.net wrote:>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.Using my limited understanding, I cobbled the following test
together.I've proved there are no jumps or clashes before 10,000; you mightwant
to leave it running overnight.function Gray2Bin(atom Num) atom junk  junk =
floor(Num/2) return xor_bits(Num, junk)end functionfunction binary(integer
anumber)sequence result	result={}	while anumber do		if and_bits(anumber,1)
then	--odd			result="1"&result			anumber-=1		else			result="0"&result		end
if		anumber/=2	end while	return resultend functioninteger i, diffs,
comparefromsequence result,prevresultprevresult=binary(Gray2Bin(1))	-- "1"i=2
comparefrom=2	-- "11"atom aa=time()+1while 1 do	result=binary(Gray2Bin(i))	if
length(result)=length(prevresult) then		diffs=0		for k=1 to length(result)
do			if result[k]!=prevresult[k] then				diffs+=1			end if		end for		if diffs!=1
then			?9/0		end if		for k=comparefrom to i-1 do			if
equal(result,binary(Gray2Bin(k))) then				?9/0			end if		end for	else		if not
equal(result[2..length(result)],prevresult) then			?9/0		end
if		comparefrom=i	end if	prevresult=result	if a<time() then		printf(1,"%d
%s\n",{i,result})		a=time()+1	end if	i+=1end whilePete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu