1. Binary conversion
- Posted by Jonas Temple <jktemple at yhti.net> Aug 15, 2002
- 428 views
Okay, I asked this a while back and now I've got a slightly different problem. If I have a sequence of {0,0,0,2} that is supposed to represent a binary number, how do I convert that to an atom? Jonas
2. Re: Binary conversion
- Posted by Derek Parnell <ddparnell at bigpond.com> Aug 15, 2002
- 440 views
Not sure what you mean by "binary". I normally regard binary numbers as only having ones and zeros. Thus {0,0,0,2} doesn't fit my idea of a binary number 'cos it has a '2' in it. Or does this sequence represent a 4-byte number, with each element having the range 0-255? In that last case the atom could be ((((s[1] * 256)+s[2])*256)+s[3])*256)+s[4] ---------------- cheers, Derek ----- Original Message ----- From: "Jonas Temple" <jktemple at yhti.net> To: "EUforum" <EUforum at topica.com> Sent: Friday, August 16, 2002 7:46 AM Subject: Binary conversion > > Okay, I asked this a while back and now I've got a slightly different > problem. > > If I have a sequence of {0,0,0,2} that is supposed to represent a binary > number, how do I convert that to an atom? > > Jonas > > > >
3. Re: Binary conversion
- Posted by Derek Parnell <ddparnell at bigpond.com> Aug 16, 2002
- 435 views
Jonas If peek({m,4}) returns {0,0,0,90} and you want that to represent the value 90, then do this: sequence s atom a s = peek({m,4}) a = s[4] + s[3] * 256 + s[2] * 65536 + s[1]*16777216 ----------- cheers, Derek ----- Original Message ----- From: "Jonas Temple" <jktemple at yhti.net> To: "EUforum" <EUforum at topica.com> Sent: Friday, August 16, 2002 10:54 AM Subject: RE: Binary conversion > > I really wrote the last post in a moment of frustration. > > What I didn't quite have a grasp on is the fact that if you do a poke4 > of an atom with a value of 90 to memory and then do a peek({mem,4}) at > the same location you get {90,0,0,0}. The PC expert would say, "Well, > duh, a PC stores binary numbers with significant digit first!" (or > last...no first...oh, whatever). What I've been working on is wrappers > for DLLs that interface to an IBM iSeries. IBM's method is to store > significant digits last so your 90 would look like {0,0,0,90}. I tried > doing a value() against my {0,0,0,90} which returned nothing (as it > should). > > So that's why I wondered about binary conversion. Still wondering on > how to turn {0,0,0,90} back into 90. I'm gonna keep diggin'. > > Jonas > > > >