Sign in to follow this  
Followers 0
Xand3r

Int() returning wrong value?

7 posts in this topic

#1 ·  Posted (edited)

int(0xffff)=65535
int(binarymid(0xffff0000,3,2))=255 ;binarymid(0xffff0000,3,2)=0xffff
int(string(binarymid(0xffff0000,3,2)))=65535
any ideea why this would occur?

$ss=BinaryMid(0xffff0000,3,2)
MsgBox(0 ,"a test" , $ss & ":" & Int($ss) & @CRLF & "0xFFFF" & ":" & Int("0xFFFF") & @CRLF & "String("&$ss & "):" & Int(String($ss)))
Edited by Xand3r

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Share this post


Link to post
Share on other sites



Kinda strange until I did a little bit of testing:

$binary = "0xff12dd12345671"
MsgBox (0, "1 - returns 2", BinaryMid($binary,1,1))
MsgBox (0, "2 - returns 4", BinaryMid($binary,1,2))
MsgBox (0, "3 - returns 6", BinaryMid($binary,1,3))
MsgBox (0, "4 - returns 8", BinaryMid($binary,1,4))
MsgBox (0, "5 - returns 10", BinaryMid($binary,1,5))
;Notes1: Number of "bytes" to extract  1 byte = 2 hex characters
;Notes2: when the number ($binary) has an odd number of characters, the above function returns bad data

To address your issue:

$ss=BinaryMid(0xffff0000,3,1)
MsgBox(0 ,"a test" , $ss & ":" & Int($ss))

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$binary = "0xff12dd12345671"
MsgBox (0, "test", "" & _
"Int("&BinaryMid($binary,1,2)&"):"&@TAB&Int(BinaryMid($binary,1,2))& @CRLF & _
"Int(String("&BinaryMid($binary,1,2)&")):"&Int(String(BinaryMid($binary,1,2)))& @CRLF & _
"Int(0xff12):"&@TAB&Int(0xff12))

you didn't address anything mate... my problem is not with binarymid... :| is with int

binarymid(value1) = value2
int(binarymid(value1)) < int (value2)

edit:

int(binarymid($binary,$x,$y)) never returns more than 255 but int has a limit of 65535... 
int(string(binarymid($binary,$x,$y))) return the right value AND
int("0xXXXX") also return the right value (X=any hex char)

bug?

Edited by Xand3r

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Share this post


Link to post
Share on other sites

It's just that Int does not operate on binary parameters.

I think it should return 0 and set @error to 1 when you pass a binary value.

From the help

Failure: Returns 0 sets @error to 1 if not an integer, float or string.

Though it would make sense for Int to be able to handle binary data.

I would say that not returning 0 and setting @error to 1 when passed binary data is a bug, and having Int handle binary data is a feature request.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

@Xand3r: Interest, I didn't know that Binary data couldn't be converted with Int or Number (tested that myself)

However, change your first line to this (from 1st post), and it works:

$ss='0x'&Hex(BinaryMid(0xffff0000,3,2))

Share this post


Link to post
Share on other sites

It's just that Int does not operate on binary parameters.

I think it should return 0 and set @error to 1 when you pass a binary value.

From the help

Though it would make sense for Int to be able to handle binary data.

I would say that not returning 0 and setting @error to 1 when passed binary data is a bug, and having Int handle binary data is a feature request.

tnx martin >_< that was the answer i was looking for :( and i know now why using string() worked :(


Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

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