如何将十六进制值转换为ASCII? [英] How to convert a hexadecimal value to ASCII?
本文介绍了如何将十六进制值转换为ASCII?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Dim buffer As String
Dim c As Char = Chr(9)
Dim fs As System.IO.FileStream = New System.IO.FileStream(test.exe,IO.FileMode.OpenOrCreate)
Dim w As System.IO.BinaryWriter =新的System.IO.BinaryWriter(fs)
w.Seek(0,System.IO.SeekOrigin.Begin)
w.Write(十六进制值在这里)
w.Close()
fs.Close()
ASCII我已经尝试过的东西,如:
MessageBox.Show(ChrW(Convert.ToInt32(48,16)))
MessageBox.Show(Chr(CInt(& H&48)))
MessageBox.Show(Chr(CInt(& H48)))
然而,这些函数中的每一个都只能用于单个字符。如何使这些函数适用于整个字符串? 我发布了另一个答案。
Dim st As String =49204c6f76652050726f6772616d6d696e672e
Dim com As String
For x = 0 To st.Length - 1 Step 2
Dim k As String = st.Substring(x,2)
com& = System.Convert.ToChar(System。 Convert.ToUInt32(k,16))。ToString()
Next
你也可以使用下面的代码函数:
Dim st As String =49204c6f76652050726f6772616d6d696e672e
Dim com As String
For x = 0 To st.Length - 1 Step 2
com& = ChrW(CInt(& H& st.Substring(x,2)))
下一个
I am trying to use fstream to write an executable file:
Dim buffer As String
Dim c As Char = Chr(9)
Dim fs As System.IO.FileStream = New System.IO.FileStream("test.exe", IO.FileMode.OpenOrCreate)
Dim w As System.IO.BinaryWriter = New System.IO.BinaryWriter(fs)
w.Seek(0, System.IO.SeekOrigin.Begin)
w.Write(HEX VALUES HERE)
w.Close()
fs.Close()
To convert the hex to ASCII I have tried things such as:
MessageBox.Show(ChrW(Convert.ToInt32("48", 16)))
MessageBox.Show(Chr(CInt("&H" & "48")))
MessageBox.Show(Chr(CInt("&H48")))
However each of those functions will only work with a single character. How do I make those functions work for entire strings?
解决方案
I am posting another answer. You can use the below code to implement your functionality.
Dim st As String = "49204c6f76652050726f6772616d6d696e672e"
Dim com As String
For x = 0 To st.Length - 1 Step 2
Dim k As String = st.Substring(x, 2)
com &= System.Convert.ToChar(System.Convert.ToUInt32(k, 16)).ToString()
Next
You can also use the below code function:
Dim st As String = "49204c6f76652050726f6772616d6d696e672e"
Dim com As String
For x = 0 To st.Length - 1 Step 2
com &= ChrW(CInt("&H" & st.Substring(x, 2)))
Next
这篇关于如何将十六进制值转换为ASCII?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文