[英]How to make a 4 bit binary to 8bit binary number?
I am using C# I have a variable byte a=0b00001111
. 我正在使用C#我有一个可变
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
当我在控制台上打印时,它显示为截断值:
1111
我想打印它原样: 00001111
I want a GENERALIZED method or code snippet which does the exact same thing which I want. 我想要一个GENERALIZED方法或代码片段来完成我想要的完全相同的事情。 I tried ANDing it with
11111111
but still the same answer. 我尝试用
11111111
但仍然是相同的答案。
Please help. 请帮忙。
Presumably just left-pad? 大概只是左撇子?
byte a = 0b00001111;
var s = Convert.ToString(a, 2).PadLeft(8, '0');
Console.WriteLine(s);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.