Sign in to follow this  
Followers 0
JoeCool

strange binarie noob question ....

14 posts in this topic

why 0x00270FF6 != 2559990 ?

unsigned hex positive int32

can someone explain me that please

if  binary("0x00270FF6") = 2559990 then
   msgbox(0, "True", "" )
else
   msgbox(0, "False", "" )
endif

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use Dec() instead. Binary() is for strings.

$Val=Dec("00270FF6")
if  $Val = 2559990 then
   msgbox(0, "True", "" )
else
   msgbox(0, "False", "" )
endif

Edit:Clarity

Edited by FuryCell

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

oh i see i found it....

binary( ) has nothing to do with hex number neither binary NUMBER (b10010100) ...

it can take 2 forms of string not interpreted the same way...

binary("abc") = binary("0x616263")

$str = binary("hello world")

is the same has

$str = stringToBinary("hello world")

who will just encode caracters to ascii byte default encoding value ...

:idea:

and binary("0x616263") is a raw encoding form ...

:)

EDIT i changed this message a few time... i was exploring the help file :(

Edited by JoeCool

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

standard strings are null terminated and thus Chr(0) will cause problems. This makes reading binary files fail because it will stop at the chr(0) which are common in binary files.

Edit:updated after clarification by Jos

Edited by FuryCell

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

A string cannot contain a NULL character as that terminates the string, Binary can.

yes , of course :idea:

maybe usuful when i will code some read/write byte port (com, lpt, usb ... ) drivers in autoit ...

something like ...

$arr[1024] stuff with all strings and all protocol bytes (0x00 to 0xFF )

stringToBinary(stringFromASCIIArray($arr)) to have a byte buffer

...

i should stop drinking beer now and go to sleep ! :)

Edited by JoeCool

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

i should stop drinking beer now and go to sleep ! :idea:

You are in the same time zone as me. Its past 6 am and I'm still awake. What is it with us geeks and not sleeping? :)

Edited by FuryCell

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

A string cannot contain a NULL character as that terminates the string, Binary can.

So StringToASCIIArray and StringFromASCIIArray functions are special from this point of view.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

So StringToASCIIArray and StringFromASCIIArray functions are special from this point of view.

Probably more than one line is needed to explain handling properly. Context is very important.

$sString = "abc" & Chr(0) & "def" & Chr(0) & "ghi"

ConsoleWrite("AutoIt type is: " & VarGetType($sString) & @CRLF)
ConsoleWrite("StringLen is " & StringLen($sString) & @CRLF)
ConsoleWrite("First NULL is character No" & StringInStr($sString, Chr(0), 0, 1) & @CRLF)
ConsoleWrite("Second NULL is character No" & StringInStr($sString, Chr(0), 0, 2) & @CRLF)
ConsoleWrite("By replacing NULL with X I get " & StringReplace($sString, Chr(0), "X") & @CRLF)
;...
ConsoleWrite("Is string terminated by NULL character?" & @CRLF)

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Thanks for being less lazy/tired than I was.

I try to avoid such situations like the plague as they are very error-prone, particularly when long-term maintenance is in view. Hence, unless NULs are imposed by external conditions, I stay away of them in any language where strings are zero-terminated. If unavoidale I treat them as arrays, collections, streams, lists, flux, ... whatever containers of suitable character type.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

AutoIt is great because its String...() functions, even RegExp (emphasizing this as a proof of something) handles NULL with no problems. Seems there are no limitations introduced additionally.

I guess if some CE hax0r would know that there would be much less Nomadmem...whatever.au3 uber-scanning memory slow omg help me questions, if nothing.

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
:idea:

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

More to the OP's original mistake: Binary is stored in memory in byte order. In other words Binary("0x00270FF6") is stored as the bytes 00,27,0F,F6. However on Windows machines, integers are stored in Little Endian format, meaning 0x00270FF6 (or 2559990) is stored as the bytes F6,0F,27,00. So,

ConsoleWrite(Int(Binary("0xF60F2700")) & @CRLF) ; = 2559990
; actual bytes
ConsoleWrite(Binary(0x00270FF6) & @CRLF)
ConsoleWrite(Binary(2559990) & @CRLF)
Edited by wraithdu

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