Convert Byte to Bit Pattern

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone tell me how to convert a byte to bit pattern?

e.g. Byte b = 1; after conversion = 00000001

Tedmond
 
Tedmond said:
Can anyone tell me how to convert a byte to bit pattern?

e.g. Byte b = 1; after conversion = 00000001

Convert.ToString(byte value, int base)

eg

byte b = 1;
Console.WriteLine (Convert.ToString(b, 2));

Note that that won't pad the result with zeroes. You'll need to do
something like:

Convert.ToString(b, 2).PadLeft(8, '0')
 
Back
Top