I have a string:
LogoDataStr = \"ABC0000\"
I want to convert to ASCII bytes and the result should be:
LogoDataBy[0] = 0x41;
class CustomAscii
{
private static Dictionary dictionary;
static CustomAscii()
{
byte numcounter = 0x30;
byte charcounter = 0x41;
byte ucharcounter = 0x61;
string numbers = "0123456789";
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string uchars = "abcdefghijklmnopqrstuvwxyz";
dictionary = new Dictionary();
foreach (char c in numbers)
{
dictionary.Add(c, numcounter++);
}
foreach (char c in chars)
{
dictionary.Add(c, charcounter++);
}
foreach (char c in uchars)
{
dictionary.Add(c, ucharcounter++);
}
}
public static byte[] getCustomBytes(string t)
{
int iter = 0;
byte[] b = new byte[t.Length];
foreach (char c in t)
{
b[iter] = dictionary[c];
//DEBUG: Console.WriteLine(b[iter++].ToString());
}
return b;
}
}
This is how i would do it. JUST IF Encoding.ASCII.GetBytes() would return wrong values.