I have a method that will check a character input, and according to the entered character will return an array of bytes consisting of 1's and 0's
(i.e) in case 2 is passed to the method I will get.
b[0] = 0
b[1] = 0
b[2] = 0
b[3] = 0
b[4] = 1
b[5] = 0
The method I tried to implement is returning the ascii equivalent of the 1's and 0's
Is there another way instead of using the below code?
private byte[] determineOutput(char c)
{
string s="";
System.Text.Encoding enc = System.Text.Encoding.ASCII;
switch (c)
{
case '0':
s = "000000";
break;
case '1':
s= "000001";
break;
case '2':
s = "000010";
break;
case 'A':
s = "001010";
break;
default:
Console.WriteLine("Invalid Characther");
break;
}
byte[] b = enc.GetBytes(s);
for (int i = 0; i < b.Length; i++)
{
Console.Write(b[i]);
}
Console.WriteLine();
return (b);
}