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...
|
Not Categorized, Please Help
|
|