1. atom_to_float32() and Hex representation
hello fellow euphorians,
my question involves the use of atom_to_float32/64() and repesentation of
hexadecimal numbers in Euphoria. I need to read a four digit long hex number from
an SLE in David Cuny's TextGUI package. The user is supposed to enter the number
already in hex. How do i convert that string to a float properly and retain is
hex value?
thanks in advance.
CenSe,
a member of the
ak-software
development team
http://ak-software.virtualave.net/
2. Re: atom_to_float32() and Hex representation
On Thu, 20 Apr 2000 05:46:37 +0400, CenSe <cense at MAIL.RU> wrote:
> How do i convert [a hex] string to a float properly and retain is value?
/me roots around for my basebag.e
/me doesn't find it.
/me curses.
It'll have to be code then:
-- I'm assuming that the hex string is in UPPER CASE --
-- I'm also not checking for bad characters --
sequence hexstring -- this is the sle input
atom hexval -- will contain the value of the hex string
integer digit
hexval = 0
for i = 1 to length(hexstring)
digit = hexstring[i]
hexval = 16 * hexval + digit - '0' - 7 * (digit>='A')
end for
Or you can do it this way (this includes a bit of error checking):
constant hexits = '0123456789ABCDEF'
sequence hexstring
atom hexval
integer digit
for i = 1 to length(hexstring)
digit = find(hexstring[i], hexits)
if digit then
hexval = 16 * hexval + digit - 1
else
error("bad digit!") -- put your own code here
end if
end for
HTH,
Carl
--
Carl R. White - Software Tester @ CTD - Carl- at -comodo.net
Cyrek the Illogical - Geek - cyrek- at -bigfoot.com
Remove hyphens before mailing s'il vous plait...
3. Re: atom_to_float32() and Hex representation
Thanks Carl,
Your code should help me alot, thanks. I may have a futher question later, but
for now, its all good.
lates
CenSe,
a member of the
ak-software
development team
http://ak-software.virtualave.net/