Language
C
Compiler
gcc 12.1.0
Options
Warnings
C11
no pedantic
#include <stdio.h>
#define INSTRUCTION_SIZE 4
unsigned char instruction[INSTRUCTION_SIZE] = {0x7F, 0xF0, 0x01, 0x13};
void print_first_instruction(unsigned char* instruction) {
unsigned char value = instruction[0];
unsigned char last_seven_bits = value & instruction[0];
char bit0 = 0x00;
printf("\nLast 7 bits in binary: ");
for (int i = 6; i >= 0; i--) {
bit0 |= (last_seven_bits >> i) & 0x01; // shift the bits and use bitwise OR to assign the bits to bit0
bit0 <<= 1; // shift bit0 to the left to make space for the next bit
printf("%d", (last_seven_bits >> i) & 0x01);
if(bit0 == 0x13){
printf("Add command");
}
}
}
int main(int argc, char *argv[]) {
print_first_instruction(instruction);
return 0;
}
$ gcc prog.c -Wall -Wextra -std=c11
Last 7 bits in binary: 1111111
Exit Code:
0