#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
void Bin_to_ByteArray(){
FILE *file;
unsigned long fsize,i;
unsigned char *buffer = NULL;
file = fopen("/路径/file.bin", "rb");
if (!file) {
printf("can't open file %s", "file.bin");
exit(1);
}
fseek(file, 0, SEEK_END);
fsize=ftell(file);
fseek(file, 0, SEEK_SET);
printf("fsize == %ld\n",fsize);
buffer=(char *)malloc(fsize+1);
if (!buffer) {
printf("Memory error!");
fclose(file);
exit(1);
}
fread(buffer, 1, fsize+1, file);
fclose(file);
for(i = 0;i < fsize ;i++) {
printf("%2x ",buffer[i]);
if(i%32==31)printf("\n");
if(i%4==3)printf(" ");
}
printf("\n");
}