Sign in to follow this  
Followers 0
amarcruz

To Bin or not to Bin :-)

7 posts in this topic

I'm not a math guru and I don't understand Binary:

Test("A", Binary("0xFF00"))
Test("B", Binary(0xFF00))
Test("C", 0xFF00)
Func Test($nam, $val)
ConsoleWrite($nam &": "& $val &@CR)
ConsoleWrite("Number: "& Number($val) &", Int: "& Int($val) & _
", Hex: "& Hex($val) &", Dec: "& Dec($val) &", 0+"& $nam &": "& (0+$val) &@CR)
EndFunc

Output:

A: 0xFF00
Number: 255, Int: 255, Hex: FF00, Dec: 0, 0+A: 0
B: 0x00FF0000
Number: 65280, Int: 65280, Hex: 00FF0000, Dec: 0, 0+b: 0
C: 65280
Number: 65280, Int: 65280, Hex: 0000FF00, Dec: 414336, 0+n: 65280

Note the Hex/Dec output.

Share this post


Link to post
Share on other sites



And the question is?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

The binary data type is a direct representation of the bits stored in memory.

Binary("0xFF00") interprets the string 0xFF00 as a list of byte values and sets them to memory one after another. It allocates 2 bytes of memory, the first one will be set to 0xFF = 255, the second byte to 0x00 = 0.

Binary(0xFF00) - 0xFF00 will be read as a number. Since it fits in 32bit, a 32bit integer will be allocated with value 0x0000FF00 = 65280 Windows uses the little endian format, so the order of the bytes in memory is reversed: 00,FF,00,00 (If the number was 0x12345678 the memory would contain 0x78, 0x56, 0x34, 0x12)

If Hex is used on a binary variable, the result will be in the order stored in memory. If Hex is used on an integer, the number is in logical numeric order. For Double values, the result is probably the format in the memory (IEEE 754)

Using Int or Number on Binary data, it will be interpretet as the memory format of the type specified in flag.


*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

Share this post


Link to post
Share on other sites

I got it. 0xFF00 cast to Int32, then the value received by Binary() is [00 FF 00 00] (four bytes). Binary("0xFF00") don't cast.

...and Hex(<Binary>) <> Hex(<Number>) because Binary<>Number.

:-)

Thank you.

Share this post


Link to post
Share on other sites

...but Number(Binary(0xFF00)) = Number(0xFF00)

whatever ... I'll think about it and re-read the help file.

tnx again

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

...but Number(Binary(0xFF00)) = Number(0xFF00)

whatever ... I'll think about it and re-read the help file.

tnx again

Here:

Number(Binary(0xFF00)):
0xFF00
-> Memory: 00 FF 00 00 (read as int32)
-> Binary()
-> Memory: 00 FF 00 00 (read as binary)
-> Number()
-> Memory: 00 FF 00 00 (read as number, 4 bytes = int32)
==> 65280

Number(0xFF00)
0xFF00
-> Memory: 00 FF 00 00 (read as int32)
-> Number()
-> Memory: 00 FF 00 00 (read as int32, no change, it already was a number)
==> 65280
Edited 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

Share this post


Link to post
Share on other sites

I see now.

Thank you so much.

Share this post


Link to post
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
Sign in to follow this  
Followers 0