几个10进制和16进制之间转化的函数

只是粗略的写了写,希望能够起到抛砖引玉的作用

以下在模块:

Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
'10进制到16进制数组
Public Sub mDec2HexArr(ByVal Dec As Long, ByRef HexArray() As Byte)
CopyMemory ByVal VarPtr(HexArray(0)), Dec, 4
End Sub

'16进制数组到10进制
Public Function mHexArr2Dec(ByRef HexArray() As Byte) As Long
CopyMemory ByVal VarPtr(mHexArr2Dec), ByVal VarPtr(HexArray(0)), 4
End Function

'10进制到16进制
Public Function mDec2Hex(ByVal Dec As Long, Optional ByVal ByteLen As Long = 4) As String
    mDec2Hex = Right("00000000" & Hex$(Dec), ByteLen * 2)
End Function

'16进制到10进制
Public Function mHex2Dec(ByVal HexStr As String) As Long
mHex2Dec = "&H" & HexStr
End Function

以下在窗体:

Option Explicit

Dim mBuff(3) As Byte
Dim mIndex As Long

Const mNum = 1234567890

Private Sub Form_Resize()

mDec2HexArr mNum, mBuff()

For mIndex = LBound(mBuff) To UBound(mBuff)
    Print mBuff(mIndex)
    Print mDec2Hex(mBuff(mIndex), 1)
    Print mDec2Hex(mBuff(mIndex))
    Print
Next

Print mHex2Dec(mDec2Hex(mBuff(3), 1) & mDec2Hex(mBuff(2), 1) & mDec2Hex(mBuff(1), 1) & mDec2Hex(mBuff(0), 1))
Print mHexArr2Dec(mBuff)

End Sub

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清晨曦月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值