Option ExplicitPrivate Sub Command1_Click() Dim BtyArr() As Byte Dim S1 As String Dim i As Long
S1 = "中" BtyArr = StrConv(S1, vbFromUnicode) For i = 0 To UBound(BtyArr) Debug.Print Hex(BtyArr(i)) Next End Sub
不明白 dim a as byte dim b1 as byte ,b2 as byteb1=a if a>&hf then b2=a b1=0 end if ?
to:flyingscv(zlj) 不明白 dim a as byte dim b1 as byte ,b2 as byteb1=a if a>&hf then b2=a b1=0 end if ? 这样的话有两个问题,b1不能为0(因为是一个变量),b2化为HEX后不是0~F(肯定比它要大)。我的意思就是拆分高四位、底四位。
哦 b1=(a and &hF) b2=(a and &hF0)/16 这样就行了
是这样吧 Private Sub Command1_Click() Dim a As Byte Dim b1 As Byte, b2 As Byte a = &H78 b1 = (a And &HF) b2 = (a And &HF0) / 16 Debug.Print b1 Debug.Print b2 End Sub
BYTE的值在0~255之间变化,将其HEX后变为0~FF。
现要将其分为两个BYTE,既一个BYTE表示0~F,另一个用0~F表示F0~FF。
如何实现?
Dim BtyArr() As Byte
Dim S1 As String
Dim i As Long
S1 = "中"
BtyArr = StrConv(S1, vbFromUnicode)
For i = 0 To UBound(BtyArr)
Debug.Print Hex(BtyArr(i))
Next
End Sub
dim a as byte
dim b1 as byte ,b2 as byteb1=a
if a>&hf then
b2=a
b1=0
end if
?
不明白
dim a as byte
dim b1 as byte ,b2 as byteb1=a
if a>&hf then
b2=a
b1=0
end if
?
这样的话有两个问题,b1不能为0(因为是一个变量),b2化为HEX后不是0~F(肯定比它要大)。我的意思就是拆分高四位、底四位。
b1=(a and &hF)
b2=(a and &hF0)/16
这样就行了
Private Sub Command1_Click()
Dim a As Byte
Dim b1 As Byte, b2 As Byte
a = &H78
b1 = (a And &HF)
b2 = (a And &HF0) / 16
Debug.Print b1
Debug.Print b2
End Sub
Debug.Print b2