I have a string:
LogoDataStr = "ABC0000"
I want to convert to ASCII bytes and the result should be:
LogoDataBy[0] = 0x41;
LogoDataBy[1] = 0x42;
LogoDataBy[2] = 0x43;
LogoDataBy[3] = 0x30;
LogoDataBy[4] = 0x30;
LogoDataBy[5] = 0x30;
LogoDataBy[6] = 0x30;
I've tried using this way:
byte[] LogoDataBy = ASCIIEncoding.ASCII.GetBytes(LogoDataStr);
But the result I get is this:
LogoDataBy[0] = 0x41;
LogoDataBy[1] = 0x42;
LogoDataBy[2] = 0x43;
LogoDataBy[3] = 0x00;
LogoDataBy[4] = 0x00;
LogoDataBy[5] = 0x00;
LogoDataBy[6] = 0x00;
Is there any wrong with my coding?
This code
class Program
{
static void Main(string[] args)
{
byte[] LogoDataBy = ASCIIEncoding.ASCII.GetBytes("ABC000");
}
}
produces expected output

Double check your code and the value of the string before you read ASCII bytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With