Bytes to Binary in C

后端 未结 6 742
情书的邮戳
情书的邮戳 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:58

    The problem you're having is that your assignment isn't resulting in a true or false value.

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

    This gets the value of the bit. You need to see if the bit is on or off, like this:

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

提交回复
热议问题