你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
tohex()
将输入转换为十六进制字符串。
语法
tohex(
value,
[,
minLength ])
详细了解语法约定。
参数
客户 | 类型 | 必需 | Description |
---|---|---|---|
value | int 或 long | ✔️ | 转换为十六进制字符串的值。 |
minLength | int |
表示要在输出中包含的前导字符数的一个值。 支持介于 1 和 16 之间的值。 大于 16 的值将被截断为 16。 如果字符串比没有前导字符的 minLength 长,则实际上会忽略 minLength。 负数仅按其基础数据大小表示,因此对于整数(32 位),minLength 至少为 8,对于长(64 位),则它至少为 16。 |
返回
如果转换成功,则结果为字符串值。
如果转换不成功,则结果 null
。
示例
以下示例检查 tohex()
整数转换是否生成预期的十六进制值。
print
tohex(256) == '100',
tohex(-256) == 'ffffffffffffff00', // 64-bit 2's complement of -256
tohex(toint(-256), 8) == 'ffffff00', // 32-bit 2's complement of -256
tohex(256, 8) == '00000100',
tohex(256, 2) == '100' // Exceeds min length of 2, so min length is ignored.
输出
print_0 | print_1 | print_2 | print_3 | print_04 |
---|---|---|---|---|
true | true | true | true | true |