Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / December 2005

Tip: Looking for answers? Try searching our database.

Convert Byte to Bit Pattern

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tedmond - 28 Dec 2005 07:39 GMT
Can anyone tell me how to convert a byte to bit pattern?

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

Tedmond
Jon Skeet [C# MVP] - 28 Dec 2005 07:54 GMT
> 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')

Signature

Jon Skeet - <skeet@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

edi - 28 Dec 2005 08:03 GMT
byte b=9;
string res="";
for (int i=7;i>=0;i++)
res+=((b>>i) & 1).ToString();

> Can anyone tell me how to convert a byte to bit pattern?
>
>  e.g. Byte b = 1;  after conversion = 00000001
>
> Tedmond

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.