十六进制到十进制 [英] Hexadecimal to decimal

查看:333
本文介绍了十六进制到十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将十六进制数转换为十进制数,但不知道如何。在AutoIt文档中(如下图所示),定义了一些常量(被指定为十六进制值):


$ b $ p $ 0x00200000 十六进制(图中带下划线)等于 8192 decimal(这是真正的转换)。但是转换器返回 2097152 。我必须转换另一个十六进制值( 0x00000200 ),但转换器错误。如何正确转换它?



当我使用定义 $ WS_EX_CLIENTEDGE (或一个十六进制值)时,它不会没有工作。如果我使用一个整数,我相信它会起作用。

解决方案

文档 - 语言参考 - 数据类型


在AutoIt中,只有一种数据类型称为Variant。变量
可以包含数字或字符串数​​据,并根据使用情况决定如何使用数据

发行:

  ConsoleWrite(0x00200000& @LF)

显示陈述的行为。使用 Int() 在转换要求的情况下:

  #region Hex2Dec 
全局常量$ 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


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.

解决方案

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

这篇关于十六进制到十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆