十进制到2位十六进制转换

十进制到2位十六进制转换

问题描述:

在我的代码中,标签26是CHOL并且我使用下面的代码将其转换为十六进制为43484f4c并使用VB6将其存储在我的数据库MS ACCESS中但现在我想将其保存为2位十六进制代码我想要分配它只有2个字节怎么可能



谢谢



我是什么尝试过:



str = Label26.Caption

bytes = StrConv(str,vbFromUnicode)

str =

对于i = LBound(字节)到UBound(字节)

str = str&格式$(十六进制$(字节(i)),00)接下来i

Label26.Caption = str

str = StrConv(bytes,vbUnicode)

rs.Fields(NameofTest)。Value = Label26.Caption

In my code label26 is "CHOL" and i'm converting it to hex as "43484f4c" using below code and storing it in my database MS ACCESS using VB6 but now i want to save it as 2-digit hex code i want to allocate it only 2 bytes how is it possible

Thank You

What I have tried:

str = Label26.Caption
bytes = StrConv(str, vbFromUnicode)
str = ""
For i = LBound(bytes) To UBound(bytes)
str = str & Format$(Hex$(bytes(i)), "00") Next i
Label26.Caption = str
str = StrConv(bytes, vbUnicode)
rs.Fields("NameofTest").Value = Label26.Caption

(Hex


( bytes(i)),00)Next i

Label26.Caption = str

str = StrConv(bytes,vbUnicode)

rs .Fields(NameofTest)。Value = Label26.Caption
(bytes(i)), "00") Next i
Label26.Caption = str
str = StrConv(bytes, vbUnicode)
rs.Fields("NameofTest").Value = Label26.Caption


不是。问题是 - 至少 - 这是四个字母字符:每个地方的'A'到'Z'。这意味着构成代码的四个字符中的每一个都有26个可能的值(如果你也允许数字,则为36个)。

两个字节只能容纳四个* 16值 - 0到65535 - 并且四个* 26需要0到456875,它们在物理上不适合两个字节。
It isn't. The problem is that - at the very least - that is four alphabetic characters: 'A' to 'Z' in each place. That means that there are 26 possible values for each of the four characters that make up your code (or 36 if you also permit digits).
Two bytes can only hold four * 16 values - 0 to 65535 - and four * 26 requires 0 to 456875 which will not physically fit in two bytes.