Hex 函数Hex function

返回表示数字的十六进制值的 StringReturns a String representing the hexadecimal value of a number.



必需的_number_ 参数是任何有效的数值表达式字符串表达式The required number argument is any valid numeric expression or string expression.

如果 numberIf number is 则 Hex 返回Hex returns
-2,147,483,648 到 2,147,483,647-2,147,483,648 to 2,147,483,647 最多八个十六进制字符Up to eight hexadecimal characters
为空Empty 零 (0)Zero (0)


如果_number_不是整数, 则在计算之前将其舍入为最接近的整数。If number is not a whole number, it is rounded to the nearest whole number before being evaluated.

对于与十六进制相反的值, 请在十六进制值前面加上 &HFor the opposite of Hex, precede a hexadecimal value with &H. 例如, Hex(255)返回字符串 FF 并&HFF返回数字255。For example, Hex(255) returns the string FF and &HFF returns the number 255.


此示例使用 Hex 函数返回一个数字的十六进制值。This example uses the Hex function to return the hexadecimal value of a number.

Dim MyHex
MyHex = Hex(5)    ' Returns 5.
MyHex = Hex(10)    ' Returns A.
MyHex = Hex(459)    ' Returns 1CB.

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.