472,110 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 software developers and data experts.

Convert Byte to Bit Pattern

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

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

Tedmond
Dec 28 '05 #1
2 2801
Tedmond <Te*****@discussions.microsoft.com> wrote:
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')

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 28 '05 #2
edi
byte b=9;
string res="";
for (int i=7;i>=0;i++)
res+=((b>>i) & 1).ToString();

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

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

Tedmond

Dec 28 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

235 posts views Thread by napi | last post: by
19 posts views Thread by Vincent | last post: by
2 posts views Thread by [Gho] | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.