说输入是
0000000000000101000000100000000011000010100000001001011000000100000111000000000111001001100000101
我写的代码是
#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;
}
然而,输出类似于
0 0 10 4 1 133 1 44 8 56 3 147 6
我认为它是以十进制打印的。如何使用包括填充位的按位运算符将这些输出转换为8位二进制数?
我想用这些二进制输入做的是做一个类似的形式:
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
任何人都可以帮我解决这个问题吗?
...谢谢