I want to display one byte in textbox. Now I\'m using:
Convert.ToString(MyVeryOwnByte, 2);
But when byte is has 0\'s at begining those 0\'s
How you do it depends on how you want your output to look.
If you just want "00011011", use a function like this:
static string Pad(byte b)
{
return Convert.ToString(b, 2).PadLeft(8, '0');
}
If you want output like "00011011", use a function like this:
static string PadBold(byte b)
{
string bin = Convert.ToString(b, 2);
return new string('0', 8 - bin.Length) + "" + bin + "";
}
If you want output like "0001 1011", a function like this might be better:
static string PadNibble(byte b)
{
return Int32.Parse(Convert.ToString(b, 2)).ToString("0000 0000");
}