2
I need to read a byte (Buffer), and convert it to Common Text, that is, I need to convert to letters and/or numbers of the ASCII table.
I am using this function to convert to ASCII Note: when I put:
string result = System.Text.Encoding.UTF8.GetString(buffer);
string result2 = System.Text.Encoding.ASCII.GetString(buffer);
string hexaSemespaco = result2.Replace("#", "");
string test = hexaSemespaco.Substring(1, (hexaSemespaco.Length - 2)); //Tem um símbolo que é ocultado
string convert = ConvertHex(test); //aqui dá o erro, parece que há conflito entre tipos de variaveis, mas não enho ctz`insira o código aqui`
public static string ConvertHex(string hexString)
{
try
{
string ascii = string.Empty;
for (int i = 0; i < hexString.Length; i += 2)
{
string hs = string.Empty;
hs = hexString.Substring(i, 2);
uint decval = System.Convert.ToUInt32(hs, 16);
char character = System.Convert.ToChar(decval);
ascii += character;
}
return ascii;
}
catch (Exception ex)
{
StreamWriter vWriterr = new StreamWriter(@"c:\POCtest.txt", true);
vWriterr.WriteLine("ERRO: " + ex.Message);
vWriterr.Flush();
vWriterr.Close();
}
return "DEU RUIM";
}
Your question is confused, you want to convert
byte[]
for ASCII text ? or want to convert to hexadecimal ?– Matheus Miranda
I want to convert byte to ASCII text, but for this I converted to hexa first, then convert to ASCII
– Leandro Kojima