Byte to Binary String C# - Display all 8 digits

前端 未结 4 949
刺人心
刺人心 2020-12-05 22:58

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

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 23:17

    You can create an extension method:

    public static class ByteExtension
    {
        public static string ToBitsString(this byte value)
        {
            return Convert.ToString(value, 2).PadLeft(8, '0');
        }
    }
    

提交回复
热议问题