Something like this?
byte b = 23;
var str = Convert.ToString(b, 2).PadLeft(8,'0');
Question
I am doing a project in which i am getting data from some switches and push buttons on the pins of 8051 MC. Now i have to transmit serially, this data on the port pins, to the PC. At the PC end i am receiving the data in C# sharp .net application using the serial port class. Now the issue is that I want that the data received in C sharp application is in the form of bit string instead of Ascii.
Can someone guide me how it can be achieved ?
Solution
Something like this?
byte b = 23;
var str = Convert.ToString(b, 2).PadLeft(8,'0');
OTHER TIPS
Characters are typically stored in sets of double bytes in C#. So for each 16 bits, cast the set of the binary to type char.
char c = (char)myBinary;
Edit: This of course depends on how many bits your project allocates to each character. It is likely it is a single byte. If this is so you will need to look into the link below for character structure.
Ref: http://msdn.microsoft.com/en-us/library/vstudio/x9h8tsay.aspx