Click here to Skip to main content
15,885,954 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to convert hexadecimal value to ASCII/extended ASCII, but the ASCII characters do not properly how in Notepad++. Instead it shows as question mark(?)

Can anybody help me to convert hex to ASCII/extended ASCII?

What I have tried:

C#
string p = "7E 3E 44 C2 80 0E C2 A0"; //"24A".PadLeft(8,'0');
var bytessss = p.Split(' ').Select(hb => Convert.ToByte(hb, 16)).ToArray(); // converts string -> byte using base 16
var asciiStr = System.Text.Encoding.ASCII.GetString(bytessss);
File.WriteAllText(@"test.txt", asciiStr, Encoding.ASCII);

Result for the above hex is: ~>D????
Posted
Updated 26-Jan-22 3:49am
v3

1 solution

Those bytes do not represent a valid sequence of ASCII characters. You cannot use the ASCII encoding to process them.

You'll need to use the appropriate encoding for your text. For example:
  • ASCII: ~>D??0E??
  • ISO-8859-1: ~>D€0EÂ
  • UTF-8: ~>D€0E
  • Unicode: 㹾쉄຀ꃂ

None of these appear to be correct, so you'll need to find out which encoding was used to produce the source data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900