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 are being cuted. Example:
MyVeryOwnByte = 00001110 // Texbox shows -> 1110
MyVeryOwnByte = 01010101 // Texbox shows -> 1010101
MyVeryOwnByte = 00000000 // Texbox shows -> <Empty>
MyVeryOwnByte = 00000001 // Texbox shows -> 1
I want to display all 8 digits.
Pad the string with zeros. In this case it is
PadLeft(length, characterToPadWith)
. Very useful extension methods.PadRight()
is another useful method.You can create an extension method:
This will fill the empty space to the left with '0' for a total of 8 characters in the string
How you do it depends on how you want your output to look.
If you just want "00011011", use a function like this:
If you want output like "00011011", use a function like this:
If you want output like "0001 1011", a function like this might be better: