fget から受け取ったバイトを単純にバイナリに変換しようとしています。
値の出力に基づいて、最初のバイトの値が 49 であることがわかりました。これをバイナリ値に変換する必要があります。
unsigned char byte = 49;// Read from file
unsigned char mask = 1; // Bit mask
unsigned char bits[8];
// Extract the bits
for (int i = 0; i < 8; i++) {
// Mask each bit in the byte and store it
bits[i] = byte & (mask << i);
}
// For debug purposes, lets print the received data
for (int i = 0; i < 8; i++) {
printf("Bit: %d\n",bits[i]);
}
これは印刷されます:
Bit: 1
Bit: 0
Bit: 0
Bit: 0
Bit: 16
Bit: 32
Bit: 0
Bit: 0
Press any key to continue . . .
明らかに、これはバイナリ値ではありません。何か助けはありますか?