Kerros Posted May 16, 2012 Posted May 16, 2012 I ran into a strange issue today while updating one of my scripts. When I tried to do some simple division on a variable and then convert it to hex, I do not get the expected value returned. An example: $Size = 128*2 ConsoleWrite('128*2 = '&$Size&@CRLF) ConsoleWrite('Hex() returns: '&hex($Size)&@CRLF) $Size = 256 ConsoleWrite('256 = '&$Size&@CRLF) ConsoleWrite('Hex() returns: '&hex($Size)&@CRLF) $Size = 512/2 ConsoleWrite('512/2 = '&$Size&@CRLF) ConsoleWrite('Hex() returns: '&hex($Size)&@CRLF) Returns 128*2 = 256 Hex() returns: 00000100 256 = 256 Hex() returns: 00000100 512/2 = 256 Hex() returns: 4070000000000000 I am running version: 3.3.8.1 While I can work around this issue in the script, I would like to understand better what is going on. Thank you, Kerros Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.
JohnOne Posted May 16, 2012 Posted May 16, 2012 (edited) There have been changes to Hex() It internally detects doubles, So my guess would be that the result of a division will be classed as a double. Edited May 16, 2012 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Kerros Posted May 17, 2012 Author Posted May 17, 2012 Thanks John that was the insight that I was needing. While I'm doing error checking earlier in the script to verify that the value is an int as I expect. I was not doing so right before sending to the hex function. I tried doing the hex function on a double to verify your thought and I did get the expected result ConsoleWrite('Hex on a double: '&hex(52.5)&@CRLF) Output: Hex on a double: 404A400000000000 Posting an example of the solution $Size = Int(512/2) ConsoleWrite('512/2 = '&$Size&@CRLF) ConsoleWrite('Hex() returns: '&hex($Size)&@CRLF) Output Int(512/2) = 256 Hex() returns: 00000100 Kerros Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.
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