Sign in to follow this  
Followers 0
dexto

Hex sanity check (possible bug)

5 posts in this topic

#1 ·  Posted (edited)

Try:

local $hexA = hex(1,2)
local $hexB = hex(140,2)

ConsoleWrite( $hexA& @CRLF)
ConsoleWrite( $hexB& @CRLF)

$hexC = $hexB - $hexA
ConsoleWrite( $hexC& @CRLF)

Output: 

01
8C
7
 
I'm not crazy right?

 

Autoit v3.3.12.0 x86

 

Edit:

This is the only way I found it works:

local $hexA = hex(1,2)
local $hexB = hex(140,2)

ConsoleWrite( $hexA& @CRLF)
ConsoleWrite( $hexB& @CRLF)

$hexC = Hex(Execute('0x'&$hexB&' - 0x'&$hexA),2)
ConsoleWrite( $hexC& @CRLF)

Output: 

01
8C
8B
 
Well this is not a bug but this IS very inconvenient. I mean hex should be fast and easy...
 
Workaround:
 
ALWAYS do operations with as - + * / with a hex variable (string) that already is in a form of "0xAF".
 
You can NOT:
$hexC = '0x'&$hexB - '0x'&$hexA

but you CAN:

$hexC = ('0x'&$hexB) - ('0x'&$hexA)
Edited by dexto

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hex is a string as you've noted above, not sure why you think it should be a valid math object.

That's like saying:

$var = "H2" + "O"
MsgBox(0, 0, $var = "water")

Should be true.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

or to put it another way...

local $h1 = 0x1
local $h2 = 0x8c

ConsoleWrite(hex($h2 - $h1) & @CRLF)

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Could always roll your own func:

ConsoleWrite(Hex(0xFE + 0xFF, 4) & ":" & _myHexMath("fe", "ff", "+", 4) & @CRLF)
 
Func _myHexMath($vVal1, $vVal2, $sMath, $iLen, $bReturnHex = True)
    If StringLeft($vVal1, 2) <> "0x" Then $vVal1 = "0x" & $vVal1
    If StringLeft($vVal2, 2) <> "0x" Then $vVal2 = "0x" & $vVal2
    Return (($bReturnHex) ? Hex(Execute($vVal1 & $sMath & $vVal2), $iLen) : _
        Execute($vVal1 & $sMath & $vVal2))
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Hex is a string as you've noted above, not sure why you think it should be a valid math object.

 

Once I realised that, everything started to make sense again.

Thanks guys.

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