Convert Hex-value in chraracter and after that in Byte

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All,

I try to convert hex-value "&HAA" in character and after that in byte

Dim sTest As String
Dim Encoder As New System.Text.ASCIIEncoding
Dim bByte() As Byte

sTest = Chr(&HAA)
bByte = Encoder.GetBytes(sTest)

As result I have "bByte = 63", but "63" is code for character "?".
Can enybody explain me this phenomenon???


Thanks in advance.

Alexander.
 
Alexander,

Not to difficult. ASCII is 7 bit code what is until 127
AA = 170

I hope this helps

Cor
 
Try this.

Dim sTest As String
Dim Encoder As New System.Text.UnicodeEncoding
Dim bByte() As Byte

sTest = Chr(&HAA)
bByte = Encoder.GetBytes(sTest)

Chris
 
Alexander Levchenko said:
I try to convert hex-value "&HAA" in character and after that in byte

Dim sTest As String
Dim Encoder As New System.Text.ASCIIEncoding
Dim bByte() As Byte

sTest = Chr(&HAA)

ASCII is always 7-bit, so there are only characters with codes 0 through
127. '&HAA' = 170, so it's not an ASCII character.
bByte = Encoder.GetBytes(sTest)

If you want to use the current Windows ANSI codepage:

\\\
bByte = System.Text.Encoding.Default.GetBytes(sTest)
///

This will return a byte array with one element containing 170.
 
Back
Top