Convet byte[] in ASCII

38 Views Asked by At

I'm trying to convert a byte[] in a string but need to use the HEX column of the ASCII table.

What i have:

*byte[] byteArray = new byte [] {41,56,41};

string result = Encoding.ASCII.GetString(byteArray, 0 ,byteArray.Length);*

Result expected:

AVA

What i got

)8)

If you could help me with this would be perfect. Thanks.

2

There are 2 best solutions below

0
Blindy On

If I understand correctly, what you want is to write the input values in hex as such:

var byteArray = new byte [] { 0x41, 0x56, 0x41 };
0
OldBoy On

The conversions are correct. You are using decimal numbers to do the conversion, which translate to the Hexadecimal values 0x29, 0x38, 0x29, which map to the characters that you see. You can get the correct values for the characters you want from any ASCII table. The Windows Character Map application is a good example.