Saying that the input is
0000000000000101000000100000000011000010100000001001011000000100000111000000000111001001100000101
The code I wrote is
#include <stdio.h>
#define BYTE unsigned char
int main(int n_args, char** vargs)
{
char* filename = vargs[1];
BYTE buffer;
FILE *file_ptr = fopen(filename,"rb");
fseek(file_ptr, 0, SEEK_END);
size_t file_length = ftell(file_ptr);
rewind(file_ptr);
for (int i = 0; i < file_length; i++)
{
fread(&buffer, 1, 1, file_ptr); // read 1 byte
printf("%d ", (int)buffer);
}
return 0;
}
However, the output is something like
0 0 10 4 1 133 1 44 8 56 3 147 6
I think it is printed as decimal. How can I convert those outputs into 8-bits binary numbers using bitwise operators including padding bits?
What I want to do with those binary inputs is to make a form of something like:
0000 # padding
0000 0000 # function 0 with 0 arg
00010000 00 0000011 10 000 # MOV 16 to 0x03
0000010 10 000 01 000 # MOV 0x02 to r0
00000101 00 000 01 000 # MOV 5 to r0
000 01 001 01 100 # ADD r0 r1
000 01 0000010 10 000 # MOV r0 to 0x02
00001000 00 0000011 10 000 # MOV 8 to 0x03
0000011 10 010 # POP 0x03
011 # RET
00001000 # 8 instructions
Can anyone please help me out with this problem?
Thanks...