共用方式為


tohex()

適用於:✅Microsoft網狀架構✅✅✅

將輸入轉換成十六進位字串。

語法

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