Bytes para Binário em C
Estou tentando simplesmente converter um byte recebido de fget em binário.
Eu sei que o valor do primeiro byte foi 49 baseado na impressão do valor. Agora preciso converter isso em seu valor binário.
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]);
}
Isto irá imprimir:
Bit: 1
Bit: 0
Bit: 0
Bit: 0
Bit: 16
Bit: 32
Bit: 0
Bit: 0
Press any key to continue . . .
Claramente, este não é um valor binário. Qualquer ajuda?