1

I have to convert a hexadecimal number to decimal, but don't know how. In the AutoIt documentation (pictured below) some constants (being assigned hexadecimal values) are defined:

a hexadecimal number from AutoIt's documentation

0x00200000 hexadecimal (underlined in image) equals 8192 decimal (this is the true conversion). But convertors return 2097152. I have to convert another hex value (0x00000200), but convertors get it wrong. How to correctly convert it?

When I use the definition $WS_EX_CLIENTEDGE (or a hexadecimal value), it doesn't work. If I use an integer I believe it will work.

user4157124
  • 2,809
  • 13
  • 27
  • 42
mhmtemnacr
  • 185
  • 3
  • 18
  • 2
    8192 is 0x2000, the value you have *is* 2097152 which is the same as the windows WS_VSCROLL constant – Alex K. May 18 '15 at 13:40
  • 2
    You have learnt wrong. `0x00200000` is not decimal 8192. You can verify this yourself using Windows Calculator (put it in programmer's mode using the *View* menu). Check the *Hex* radio button, type in `200000`, and then click the *Dec* button. When reading hex numbers, you can drop any leading zeros - `0x00200000` is the same as `0x200000`, and `0x00000200` is the same as `0x200`. – Ken White May 18 '15 at 13:48

1 Answers1

3

As per Documentation - Language Reference - Datatypes:

In AutoIt there is only one datatype called a Variant. A variant can contain numeric or string data and decides how to use the data depending on the situation it is being used in.

Issuing:

ConsoleWrite(0x00200000 & @LF)

demonstrates stated behavior. Use Int() in case of conversion requirement:

#region Hex2Dec
Global Const $dBin1 = 0x00200000
Global Const $iInt1 = Int($dBin1)

ConsoleWrite($iInt1 & @LF)
#endregion

#region Dec2Hex
Global Const $iInt2 = 8192
Global Const $dBin2 = Hex($iInt2)

ConsoleWrite('0x' & $dBin2 & @LF)
#endregion

Related functions include:

user4157124
  • 2,809
  • 13
  • 27
  • 42