十进制到2位十六进制转换 [英] Decimal to 2 digit hex conversion

查看:83
本文介绍了十进制到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.


这篇关于十进制到2位十六进制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆