469,314 Members | 2,151 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,314 developers. It's quick & easy.

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 2719
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.