如何将textbox中的字符串转化为16进制数
比如在TEXTBOX中我要输入41则如何让计算机识别为16进制的0x41。
意思是不让计算机认为这是一个两字节的“41”字符串,而是一个字节的。
再有,如果输入41 55 66
则让计算机认为是0x410x550x66
既是3个字节的 --------------------编程问答-------------------- VB中:
Dim TheTestString As String = TextBox.text
Dim TestString() As String = TheTestString.Split(" ")
Dim TestBytes(TestString.Length - 1) As Byte
For i As Integer = 0 To TestString.Length - 1
TestBytes(i) = "&H" + TestString(i)
Next
TestBytes里存的就是十六进制数了。
--------------------编程问答--------------------
--------------------编程问答-------------------- 我现在做出来输入55,计算机还是认为是两个字节啊! --------------------编程问答-------------------- CType(txtBox.Text,int16)
Dim s As String = "41"
Dim n As Integer
n = CInt("&h" & s)
就可以了 --------------------编程问答-------------------- 我要的是计算机将其辨认为16进制,然后放在Dim sendBytes() As Byte数组中发送出去! --------------------编程问答--------------------
--------------------编程问答--------------------
Dim myBytes() As Byte //十六进制数组
myBytes=BitConverter.GetBytes(TextBox1.Text);
--------------------编程问答--------------------
Dim myBytes() As Byte //十六进制数组
myBytes=BitConverter.GetBytes(TextBox1.Text);
Dim bt As Byte = Convert.ToByte ("41", 16)--------------------编程问答-------------------- 学习。。。
--------------------编程问答-------------------- CType(txtName.Text, Int16)‘转换16进制数
补充:.NET技术 , VB.NET