Jump to content

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.

Link to comment
Share on other sites

And the question is?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
Share on other sites

...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

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...