Jump to content

Hex sanity check (possible bug)


dexto
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

  • Moderators

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.

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