lesmly Posted July 7, 2012 Share Posted July 7, 2012 Hi. If I execute command: Binary(41094.914605567130) I get 0xF2E47244DD10E440 But how I can get 41094.914605567130 from 0xF2E47244DD10E440 ??? How I can get number from binary? Link to comment Share on other sites More sharing options...
ProgAndy Posted July 7, 2012 Share Posted July 7, 2012 (edited) This is fairly simple: $b = Binary("0x...") $n = Number($b, 3) Edited July 7, 2012 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
lesmly Posted July 7, 2012 Author Share Posted July 7, 2012 but - when I try - my $n is 0 Link to comment Share on other sites More sharing options...
JohnOne Posted July 7, 2012 Share Posted July 7, 2012 but - when I try - my $n is 0When you try what?Post the exact code you "try". AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
lesmly Posted July 7, 2012 Author Share Posted July 7, 2012 Ok - this is my "code" $b = Binary("0xF2E47244DD10E440") $n = Number($b, 3) ConsoleWrite ($n & @CRLF) Link to comment Share on other sites More sharing options...
ProgAndy Posted July 7, 2012 Share Posted July 7, 2012 Maybe a bug? For now you can do this: Func _BinaryToDouble($v) Local $t = DllStructCreate("double") DllStructSetData(DllStructCreate("byte[8]", DllStructGetPtr($t)), 1, Binary($v)) Return DllStructGetData($t, 1) EndFunc *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
lesmly Posted July 7, 2012 Author Share Posted July 7, 2012 Thanks !!! This is what I need! Link to comment Share on other sites More sharing options...
elektron Posted July 11, 2012 Share Posted July 11, 2012 Not a bug. Number() is defined for values of n such that n is an integer. It says that in the manual. However, what it doesn't say in the manual is that Binary() isn't defined for doubles and floats as well. You're converting a floating point number to binary, hex, or decimal -- so you're going to have to follow IEEE specifications. It's fun & easy. Here are some resources:1). http://en.wikipedia.org/wiki/Floating_point2). http://www.h-schmidt.net/FloatConverter/IEEE754.html3). http://sandbox.mc.edu/~bennet/cs110/flt/dtof.html If nobody writes this, then I'll write something to do it myself. It seems like a good exercise though. Link to comment Share on other sites More sharing options...
ProgAndy Posted July 11, 2012 Share Posted July 11, 2012 (edited) However, what it doesn't say in the manual is that Binary() isn't defined for doubles and floats as well.Binary is defined for those values. It returns exactly what it should: the exact binary data stored in memory. It is also documented that AutoIt stores floating point numbers as doubles.Number on the other hand is not defined for binary input, although the description of the parameter only expects an "expression" It works well with everything except binary data in IEEE 754 format.If nobody writes this, then I'll write something to do it myself. It seems like a good exercise though.If you want to write it, don't wait for someone else. The conversion is already possible with the DLLStruct functions. Edited July 11, 2012 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
elektron Posted July 11, 2012 Share Posted July 11, 2012 (edited) Ah... I'm still not sure that Binary() is returning the proper representation of the number. It doesn't look right at all. Let me explain:F2 = 1111 0010E4 = 1110 010072 = 0111 001044 = 0100 0100DD = 1101 1101 10 = 0001 0000E4 = 1110 010040 = 0100 0000(Correct my math if I am wrong, I'm doing this in my head.)SO:0xF2E47244DD10E440 = 1111 0010 1110 0100 0111 0010 0100 0100 1101 1101 0001 0000 1110 0100 0100 0000= 64 bitsSO:The first digit is the sign bit, it is 1 so the number is negative. 1 = -The next set, from 62 to 52 is the exponent field, and it is:1110 0101 110Which is, in decimal1838 - 1023 = 815Next up, from 51 to 0, we have the significand, which is:0100011100100100010011011101000100001110010001000000In decimal:0.2778977046384767Add the magic bit:1.2778977046384767Now we have to do the math2^(Exponent - Bias)*Significand (with magic bit)And the result of that is: 2.7921744980454277e+245And because the sign bit is 1, we add a negative:-2.7921744980454277e+245^That's the final answer.Maybe I'm not remembering my assembly correctly; however, I reversed the entire operation and got the same answer back. -2.7921744980454277e+245The funny thing is. Reverse the order of the bits, and the answer is, coincidentally, what we want it to be (little endian vs big endian, maybe?)F2E47244DD10E440 =40 E4 10 DD 44 72 E4 F2... Which equals ...41094.914605567130Am I an idiot? I dont' know. I'd love to write this thing in native AutoIt. It's always nice to have stuff run in native code... And it's looking like I need to brush up on my skills. They got a little rusty after not coding in assembly for so long. Take care, -- AlexEDIT: I wanted to add -- I'm going to find my notebook and look up my notes. Edited July 11, 2012 by elektron Link to comment Share on other sites More sharing options...
ProgAndy Posted July 11, 2012 Share Posted July 11, 2012 (little endian vs big endian, maybe?) you got that right. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
elektron Posted July 15, 2012 Share Posted July 15, 2012 you got that right. Too much SPARC assembly. Doh. It's so easy to get mixed up. Link to comment Share on other sites More sharing options...
trancexx Posted July 17, 2012 Share Posted July 17, 2012 Anyway, to get hex representation of number you use Hex(): Hex(41094.914605567130) ; the result is 40E410DD4472E4F2 To get number out of hex string you Dec() it: Dec("40E410DD4472E4F2", 3) ; flag 3 means to get number of double type. elektron 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
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