Hexadecimal to decimal

我的梦境 提交于 2019-11-27 08:25:34

问题


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:

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.


回答1:


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:

  • Int()
  • Number()
  • String()
  • StringToBinary()
  • StringToASCIIArray()
  • StringFromASCIIArray()
  • Binary()
  • BinaryToString()
  • Ptr()
  • HWnd()


来源:https://stackoverflow.com/questions/30304690/hexadecimal-to-decimal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!