Search code examples
numbershexdecimalautoitdefinition

Hexadecimal to decimal


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.


Solution

  • 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: