dexto Posted January 18, 2015 Posted January 18, 2015 (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 January 18, 2015 by dexto
Moderators SmOke_N Posted January 18, 2015 Moderators Posted January 18, 2015 (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 January 18, 2015 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.
kylomas Posted January 18, 2015 Posted January 18, 2015 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
Moderators SmOke_N Posted January 18, 2015 Moderators Posted January 18, 2015 (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 January 18, 2015 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.
dexto Posted January 18, 2015 Author Posted January 18, 2015 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now