Reputation: 1824
I am using C#
I have a variable byte a=0b00001111
.
When i print it on console it shows as truncated value: 1111
I want to print it right as it is: 00001111
I want a GENERALIZED method or code snippet which does the exact same thing which I want.
I tried ANDing it with 11111111
but still the same answer.
Please help.
Upvotes: 2
Views: 2831
Reputation: 1063704
Presumably just left-pad?
byte a = 0b00001111;
var s = Convert.ToString(a, 2).PadLeft(8, '0');
Console.WriteLine(s);
Upvotes: 7