# To Bin or not to Bin :-)

## Recommended Posts

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 on other sites

And the question is?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

##### 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 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 on other sites

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

tnx again

##### Share on other sites

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

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 on other sites

I see now.

Thank you so much.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...