1. binary to decimal conversion
- Posted by Grape_ Vine_ <g__vine at HOTMAIL.COM> Oct 19, 2000
- 504 views
Does anyone have a lib that takes 2 bit binary numbers and converts to decimal? I tried it but its ugly and doesn't work. J Reeves Grape Vine ICQ# 13728824 _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. Share information about yourself, create your own public profile at http://profiles.msn.com.
2. Re: binary to decimal conversion
- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM> Oct 19, 2000
- 511 views
Hello J Reeves, >Does anyone have a lib that takes 2 bit >binary numbers and converts to decimal? >I tried it but its ugly and doesn't work. I found the following in: http://rapideuphoria.com/lib_a_b.htm#bits_to_int Is this what you need bits_to_int Syntax: include machine.e a = bits_to_int(s) Description: Convert a sequence of binary 1's and 0's into a positive number. The least-significant bit is s[1]. Comments: If you print s the bits will appear in "reverse" order, but it is convenient to have increasing subscripts access bits of increasing significance. Example: a = bits_to_int({1,1,1,0,1}) -- a is 23 (binary 10111) See Also: int_to_bits, operations on sequences According the above description, it looks like you will need to reverse the sequence of bits before sending it to bits_to_int(). Here is what I think would work: <Untested code> include machine.e -- for bits_to_int() include misc.e -- for reverse() sequence binary integer int binary = {0,1} -- 1 int = bits_to_int( reverse( binary ) ) ? int <end untested code> later, Lewis Townsend _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. Share information about yourself, create your own public profile at http://profiles.msn.com.
3. Re: binary to decimal conversion
- Posted by Grape_ Vine_ <g__vine at HOTMAIL.COM> Oct 19, 2000
- 477 views
I too have seen that. It does not work just the way i want it to Id does as long as i supply the binary by hand. I have a 128byte buffer i need changed from 8 bit binary to 2 bit binary I tried sequence slicing but it keeps giving me the old number >From: Lewis Townsend <keroltarr at HOTMAIL.COM> >Reply-To: Euphoria Programming for MS-DOS <EUPHORIA at LISTSERV.MUOHIO.EDU> >To: EUPHORIA at LISTSERV.MUOHIO.EDU >Subject: Re: binary to decimal conversion >Date: Thu, 19 Oct 2000 18:17:00 CDT > >Hello J Reeves, > >>Does anyone have a lib that takes 2 bit >>binary numbers and converts to decimal? >>I tried it but its ugly and doesn't work. > > >I found the following in: >http://rapideuphoria.com/lib_a_b.htm#bits_to_int >Is this what you need > > >bits_to_int >Syntax: include machine.e >a = bits_to_int(s) >Description: Convert a sequence of binary 1's and 0's into a positive >number. The least-significant bit is s[1]. >Comments: If you print s the bits will appear in "reverse" order, but it is >convenient to have increasing subscripts access bits of increasing >significance. >Example: >a = bits_to_int({1,1,1,0,1}) >-- a is 23 (binary 10111) > >See Also: int_to_bits, operations on sequences > >According the above description, it looks like you will need >to reverse the sequence of bits before sending it to >bits_to_int(). Here is what I think would work: > ><Untested code> >include machine.e -- for bits_to_int() >include misc.e -- for reverse() >sequence binary >integer int >binary = {0,1} -- 1 >int = bits_to_int( reverse( binary ) ) >? int ><end untested code> > > >later, >Lewis Townsend >_________________________________________________________________________ >Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. > >Share information about yourself, create your own public profile at >http://profiles.msn.com. _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. Share information about yourself, create your own public profile at http://profiles.msn.com.
4. Re: binary to decimal conversion
- Posted by Derek Parnell <derekp at solace.com.au> Oct 20, 2000
- 507 views
------=_NextPart_000_000F_01C03AA9.246E5B30 charset="iso-8859-1" Hi, I've knocked up a function that might be what you're looking for. > >I too have seen that. It does not work just the way i want it to >Id does as long as i supply the binary by hand. >I have a 128byte buffer i need changed from >8 bit binary to 2 bit binary >I tried sequence slicing but it keeps >giving me the old number > > ----- cheers, Derek Parnell ------=_NextPart_000_000F_01C03AA9.246E5B30 name="test.exw" Content-Transfer-Encoding: quoted-printable
5. Re: binary to decimal conversion
- Posted by Matthew Lewis <MatthewL at KAPCOUSA.COM> Oct 20, 2000
- 496 views
> From: Grape_ Vine_ > I too have seen that. It does not work just the way i want it to > Id does as long as i supply the binary by hand. > I have a 128byte buffer i need changed from > 8 bit binary to 2 bit binary > I tried sequence slicing but it keeps > giving me the old number This isn't completely clear, but is this what you mean: original buffer dec = { 255, 128 } => original buffer bin = { 11111111, 10101010 } => new buffer bin = { 11, 11, 11, 11, 10, 10, 10, 10 } => new buffer dec = { 3, 3, 3, 3, 2, 2, 2, 2 } if so: -- begin tested code include machine.e -- sequence buf is a sequence of integers [0-255] function convert_buffer( sequence buf ) sequence new for i = 1 to length( buf ) do -- put into binary/sequence form buf[i] = int_to_bits( buf[i] ) end for new = {} for i = 1 to length( buf ) do -- slice up the bytes into 2 bit lengths and add to new new &= { buf[i][1..2], buf[i][3..4], buf[i][5..6], buf[i][7..8] } end for buf = repeat(0, length(new) ) for i = 1 to length( new ) do -- convert back to integers from binary/sequence form buf[i] = bits_to_int( new[i] ) end for return buf end function -- end code There are probably ways that this could be sped up, but I think this gets the job done. I'm not certain how you're getting the buffer, but this should be easily modifiable. Matt
6. Re: binary to decimal conversion
- Posted by Grape_ Vine_ <g__vine at HOTMAIL.COM> Oct 20, 2000
- 483 views
Thanx, This is what i was after. Sorry for not being clear, I tend to say 3 words and think it was 30 =) J Reeves Grape Vine ICQ# 13728824 >From: Matthew Lewis <MatthewL at KAPCOUSA.COM> >Reply-To: Euphoria Programming for MS-DOS <EUPHORIA at LISTSERV.MUOHIO.EDU> >To: EUPHORIA at LISTSERV.MUOHIO.EDU >Subject: Re: binary to decimal conversion >Date: Fri, 20 Oct 2000 08:51:42 -0700 > > > From: Grape_ Vine_ > > > I too have seen that. It does not work just the way i want it to > > Id does as long as i supply the binary by hand. > > I have a 128byte buffer i need changed from > > 8 bit binary to 2 bit binary > > I tried sequence slicing but it keeps > > giving me the old number > >This isn't completely clear, but is this what you mean: > >original buffer dec = { 255, 128 } >=> >original buffer bin = { 11111111, 10101010 } >=> >new buffer bin = { 11, 11, 11, 11, 10, 10, 10, 10 } >=> >new buffer dec = { 3, 3, 3, 3, 2, 2, 2, 2 } > > >if so: > >-- begin tested code > >include machine.e > >-- sequence buf is a sequence of integers [0-255] >function convert_buffer( sequence buf ) > sequence new > > for i = 1 to length( buf ) do > -- put into binary/sequence form > buf[i] = int_to_bits( buf[i] ) > end for > > new = {} > for i = 1 to length( buf ) do > -- slice up the bytes into 2 bit lengths and add to new > new &= { buf[i][1..2], buf[i][3..4], buf[i][5..6], buf[i][7..8] } > end for > > buf = repeat(0, length(new) ) > for i = 1 to length( new ) do > -- convert back to integers from binary/sequence form > buf[i] = bits_to_int( new[i] ) > end for > > return buf >end function > >-- end code > >There are probably ways that this could be sped up, but I think this gets >the job done. I'm not certain how you're getting the buffer, but this >should be easily modifiable. > >Matt _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. Share information about yourself, create your own public profile at http://profiles.msn.com.