How to convert binary to string?

后端 未结 3 1510
野性不改
野性不改 2020-12-21 05:49
static List ConvertTextToBinary(int number, int Base)
{
    List list = new List();
    while (number!=0)
    {
        list.Add(num         


        
3条回答
  •  误落风尘
    2020-12-21 06:23

    You can convert a single bit-set to a character as follows:

    int[] h = { 1, 1, 0, 1, 0, 0, 0 };
    int result = 0;
    int bitValue = 1;
    
    for (int i = h.Length - 1; i >= 0 ; i--)
    {
        result += h[i] * bitValue;
        bitValue *= 2;
    }
    
    Console.WriteLine((char)result);
    

    Each bit corresponds to a multiple of 2. By starting at the last bit and multiplying the bit value by two, you get the result you want.

提交回复
热议问题