Conver byte to string of 1's and 0's

G

Guest

I receive input in a byte which gives a value of 0-255. Is there an easy way
to convert this to a string. The string constiting of 1's and 0's. This is
necessay because I'm looking for a certain pattern of 12 1's and 0's in a
sting of 300 bits long. The pattern can be anywhere and doesn't start at
every fourth bit or any particular position.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

In the worst case escenario this is extremely simple to do.

Of course, you have Convert.ToString( byte, int) :)
 
N

Nicholas Paldino [.NET/C# MVP]

Dave,

You can call the static ToString method on the Convert class, passing
the byte, and 2 as the toBase parameter, and it will give you the byte in
base-2 representation.

Of course, if you are looking for a specific pattern, you could just use
a bitmask, and perform shift operations, applying the bitmask every step of
the way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top