Bytes to Binary in C

后端 未结 6 726
情书的邮戳
情书的邮戳 2021-02-04 14:22

I\'m trying to simply convert a byte received from fget into binary.

I know the value of the first byte was 49 based on printing the value. I now need to convert this in

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-04 14:56

    Change

    bits[i] = byte & (mask << i);
    

    to

    bits[i] = (byte >> i) & mask;
    

    or

    bits[i] = (byte >> i) & 1;
    

    or

    bits[i] = byte & 1;
    byte >>= 1;
    

提交回复
热议问题