Alright, I have been banging my head against a wall for days with this one and am finally breaking down and asking for help. Now before anyone asks, I HAVE searched the whole forum, up and down, for information on this problem and one of the answers provided me 'some' help, but I am still at a loss... so without further a do, here we go. Post my ideas came from... I have too convert 3x 4 byte hex values that represent floats. These floats represent a point in three dimensional space, x,y,z coordinates. 0x8D2B33C6 - X Position in space 0x698FC344 - Y Position in space 0xC5524242 - Z Position in space Now they are currently in network byte order, or Big Endian and need to be converted to Little Endian. So then we have this... 0xC6332B8D 0x44C38F69 0x424252C5 - Respectivly... NOTE: The endian converter in the code handles this with the input, so this is just for ease of reading. Now using the following code: #include <String.au3>
#Include <WinAPI.au3>
$start = "698FC344"
$end = hexToFloat($start)
MsgBox(0, '', $end)
func endian_converter($value)
local $byte0 = BitShift($value,24)
local $byte1 = BitAND(BitShift($value,-8), 0x00FF0000)
local $byte2 = BitAND(BitShift($value,8), 0x0000FF00)
local $byte3 = BitShift($value,-24)
local $result = BitOR($byte0,$byte1,$byte2,$byte3)
return $result
endfunc
Func hexToFloat($hex)
return StringFormat("%f",_WinAPI_IntToFloat(endian_converter(Number("0x" & $hex))))
EndFunc I get "1564.48156738281" which is correct, however when I replace the hex with this "8D2B33C6" i get "-1.#QNAN" (should be -11466.89) About HALF of my computations return this "Quiet Not A Number" and I don't know why. I use another program that does hex/binary/float conversions and they all work out correctly there, why not here? So I guess what I'm asking is why does this not work all the time and why is it returning a QNAN for some of these values? Do I need to create my own HexToFloat32 function? If so, I have run through ALL the wikipedia and google information I can find and still don't understand how to recreate these floats from the hex data. ANY help would be appreciated here! Thanks to anyone who takes the time to read this and especially anyone who responds! ~Vaughner