Convert Hex-value in chraracter and after that in Byte

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.
 
C

Cor Ligthert

Alexander,

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

I hope this helps

Cor
 
C

Chris, Master of All Things Insignificant

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
 
H

Herfried K. Wagner [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top