如何在 Excel 中反轉我的模組以從十進制轉換為十六進制?

如何在 Excel 中反轉我的模組以從十進制轉換為十六進制?

這個問題基於這裡的模組:如何在 Excel 中將十六進位數轉換為十進位數?

我正在使用的模組(來自上面的連結)是這樣的:

Option Explicit

Public Function HexadecimalToDecimal(HexValue As String) As Double

    ' If hex starts with 0x, replace it with &H to represent Hex that VBA will understand
    Dim ModifiedHexValue As String
    ModifiedHexValue = Replace(HexValue, "0x", "&H")

    HexadecimalToDecimal = CDec(ModifiedHexValue)

End Function

我有它在做:

HexadecimalToDecimal(00007FF7BE6B0000)

這給出了正確的結果

“140702028333056”

我希望獲得有關將上述模組反轉為相反的幫助,因此十進制變回十六進制。

十進位到十六進位(140702028333056)

應該導致:

“00007FF7BE6B0000”(或顯然是“7FF7BE6B0000”)

任何幫助或指導都將不勝感激!

答案1

使用Hex()

Function myDec2Hex(val As Double) As String
    myDec2Hex = Hex(val)
End Function

在此輸入影像描述

相關內容