yxrkt Posted November 11, 2007 Posted November 11, 2007 anyone know how i can turn d89c7244 to something like 970,451 ?
Zedna Posted November 11, 2007 Posted November 11, 2007 Maybe this part of Auto3Library may help you (as inspiration): ; #FUNCTION# ==================================================================================================== ================ ; Description ...: Returns a 4 byte float as an integer value ; Parameters ....: $nFloat - Float value ; Return values .: Success - 4 byte float value as an integer ; Author ........: Paul Campbell (PaulIA) ; Remarks .......: ; Related .......: ; ==================================================================================================== =========================== Func _Lib_FloatToInt($nFloat) Local $tFloat, $tInt $tFloat = DllStructCreate("float") $tInt = DllStructCreate("int" , DllStructGetPtr($tFloat)) DllStructSetData($tFloat, 1, $nFloat) Return DllStructGetData($tInt, 1) EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search
Danny35d Posted November 11, 2007 Posted November 11, 2007 Look at the help file for _StringToHex() and _HexToString() #include <string.au3> $String = "970,451 " $Hex = _StringToHex($String) MsgBox(0, "Hex", "Original String: " & $String & @LF & " Hex: " & $Hex) $Hex = "3937302C34353120" $String = _HexToString($Hex) MsgBox(0, "Hex", "Original Hex: " & $Hex & @LF & " String: " & $String) AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
yxrkt Posted November 11, 2007 Author Posted November 11, 2007 hmm.. am i missing something ? CODE#include <String.au3> $a = '0xd89c7244' msgbox(0,'', _Lib_IntToFloat($a) & @crlf _ & _Lib_FloatToInt($a) & @crlf _ & _Lib_FloatToInt(Hex2Dec($a)) & @crlf _ & IntToFlt($a) & @crlf _ & IntToFlt(Hex2Dec($a)) & @crlf _ & Hex2Dec($a)& @crlf _ & _HexToString(stringtrimleft($a,2))) ) Func _Lib_IntToFloat($iInt) Local $tFloat, $tInt $tInt = DllStructCreate("int") $tFloat = DllStructCreate("float", DllStructGetPtr($tInt)) DllStructSetData($tInt, 1, $iInt) Return DllStructGetData($tFloat, 1) EndFunc Func _Lib_FloatToInt($nFloat) Local $tFloat, $tInt $tFloat = DllStructCreate("float") $tInt = DllStructCreate("int" , DllStructGetPtr($tFloat)) DllStructSetData($tFloat, 1, $nFloat) Return DllStructGetData($tInt, 1) EndFunc Func IntToFlt($iVal) Local $result $fs = DllStructCreate("float") $is = DllStructCreate("int64",DllStructGetPtr($fs)) DllStructSetData($is,1,$iVal) $result = DllStructGetData($fs,1) $fs = 0 $is = 0 return $result endfunc Func Dec2Bin($decimal) $binary = '' While $decimal>0 $binary = String(Mod($decimal, 2)) & $binary $decimal = Int($decimal/2) WEnd Return $binary EndFunc Func Bin2Dec($binary) $decimal = 0 For $i = 0 To StringLen($binary) Step 1 $decimal = $decimal + Number(StringMid($binary, StringLen($binary)-$i, 1))*(2^$i) Next Return $decimal EndFunc Func Hex2Dec($hexa) $decimal = 0 For $i = 0 To StringLen($hexa) Step 1 $char = StringMid($hexa, StringLen($hexa)-$i, 1) If $char='A' Then $single = 10 ElseIf $char='B' Then $single = 11 ElseIf $char='C' Then $single = 12 ElseIf $char='D' Then $single = 13 ElseIf $char='E' Then $single = 14 ElseIf $char='F' Then $single = 15 Else $single = Number($char) EndIf $decimal = $decimal + $single*(16^$i) Next Return $decimal EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now