Converting a byte to a binary string in c#

后端 未结 4 1509
不思量自难忘°
不思量自难忘° 2020-12-02 22:17

In c# I am converting a byte to binary, the actual answer is 00111111 but the result being given is 111111. Now I really

4条回答
  •  心在旅途
    2020-12-02 22:54

    public static string ByteArrayToString(byte[] ba)
    {
        StringBuilder hex = new StringBuilder(ba.Length * 2);
        foreach (byte b in ba)
            hex.AppendFormat("{0:x2}", b);
        return hex.ToString();
    }
    

提交回复
热议问题