Hi all,
I like to write out integers in binary format to the console.
Let's say I want Myint=5 to be written I use Convert.ToString(Myint,2)
I get 101, what I want is 0000000000000101
I found this struct on the net which could do the trick, but is there a better way?
struct IntBits
{
private int _bits;
public IntBits(int InitialBitValue)
{
_bits = InitialBitValue;
}
//declare indexer
public bool this[int index]
{
get
{
return (_bits & (1 << index)) != 0;
}
set
{
if (value)
_bits |= (1 << index); //set bit index 1
else
_bits &= ~(1 << index); //set bit index 0
}
}
}