Opened 4 months ago

Closed 4 months ago

Last modified 4 months ago

#3980 closed Bug (Rejected)

Hexadecimal notation in the range 0x80000000 to 0xFFFFFFFFFF

Reported by: AspirinJunkie Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:


In AutoIt, numerical values in the source code can be defined in decimal notation as well as in hexadecimal notation.
In the number range 0x80000000 to 0xFFFFFFFFFF, however, the inputs are not interpreted as hexadecimal numbers but as a binary, which is coded as an Int32 number and therefore becomes a negative number.

A distinction must be made here between the number representation in hexadecimal notation, which should still be independent of the subsequent coding when defined in the source code, and the binary coding in specific data types, which only takes place later.

So if a user writes 0x90000001 in the source code, he expects to have written the decimal number 2415919105 (see here). Instead, he receive the number -1879048191.

One solution would therefore be to always save hexadecimal values greater than 0x80000000 as Int64.

Example for clarification:

; interpreted as 32 Bit-Int
Global $a = 0x7FFFFFFF
Global $b = 0x80000000

ConsoleWrite("$a: " & $a & " (" & VarGetType($a) & ")" & @CRLF)
ConsoleWrite("$b: " & $b & " (" & VarGetType($b) & ")" & @CRLF)

; interpreted as 64 Bit-Int
Global $a = 0x07FFFFFFF
Global $b = 0x080000000

ConsoleWrite("$a: " & $a & " (" & VarGetType($a) & ")" & @CRLF)
ConsoleWrite("$b: " & $b & " (" & VarGetType($b) & ")" & @CRLF)

Attachments (0)

Change History (3)

comment:1 Changed 4 months ago by Jpm

  • Resolution set to Rejected
  • Status changed from new to closed

AutoIt try to fit hex value to minimum variable size
So 0xffffffff can be stored in an Int32
If You really wants to take care of a non negative value, as you point out, use 0x0ffffffff

comment:2 Changed 4 months ago by AspirinJunkie

Yes, it is obvious that it chooses the smallest possible coding.
However, this is not the smallest possible coding for the number range in question, which can be recognised by the fact that a completely different number is coded than was specified.
0xffffffffff cannot be coded as Int32 but only as UInt32. The hexadecimal number 0xffffffffff is different from the binary Int32 coding 0xffffffffff. One represents the number 4294967295 and the other the number -1. However, the AutoIt help indicates that the former is meant.

Once again: at this point you enter numbers - regardless of their coding. AutoIt then has to select the correct coding for this number. And it fails in this number range.
If you enter the number in decimal form, the behaviour does not occur either. The numerical value remains correct and the correct encoding has been selected. Only in hexadecimal notation (which we said is only a mathematical notation and independent of a later encoding) is the wrong encoding selected.

A bug is a deviation from the expected or documented behaviour.
The AutoIt help clearly states that integer numbers can also be defined in hexadecimal. (Negative via the sign). There is no mention of any restriction of the number range.
The behaviour therefore corresponds to a bug by definition.

comment:3 Changed 4 months ago by AspirinJunkie

I have compared the behaviour with other dynamically typing languages and none of these languages (Python, Javascript and Ruby) show the same behaviour as AutoIt.
The number range is correctly converted into the corresponding variable value.

AutoIt does its own thing here and the behaviour is not documented anywhere. The user simply cannot expect this behaviour beforehand.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The ticket will remain with no owner.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.