Jump to content

Help converting Hex 32 bit float please (reverse)


Recommended Posts

Ok, my Bitwise knowledge is pretty bad so i need a little help with this one.

This function converts the $Hex into a float:

#Include <WinAPI.au3>
#Include <String.au3>

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

$Hex = "6766CA41"

MsgBox(0,"",StringFormat("%2.16f",_WinAPI_IntToFloat(endian_converter(Number("0x" & $Hex)))))

But i need to do the opposite. From a float to a 32bit hex.

So if i type in 1 it will return : "0x0000803F"

[center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]

Link to comment
Share on other sites

Ok, my Bitwise knowledge is pretty bad so i need a little help with this one.

This function converts the $Hex into a float:

#Include <WinAPI.au3>
#Include <String.au3>

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

$Hex = "6766CA41"

MsgBox(0,"",StringFormat("%2.16f",_WinAPI_IntToFloat(endian_converter(Number("0x" & $Hex)))))

But i need to do the opposite. From a float to a 32bit hex.

So if i type in 1 it will return : "0x0000803F"

This is the easiest way I think.

$a = DllStructCreate("Int")
$b = DllStructCreate("float",DllStructGetPtr($a))
DllStructSetData($b,1,1)
ConsoleWrite("0x" & Hex(DllStructGetData($a,1)) & @CRLF)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...