用C语言,将文件以16进制的形式打印出来
方法一
void main()
{
int size = 1280 * 720 * 3 / 2;
char *buf = (char *)malloc(sizeof(char) * size);
char *str = (char *)malloc(sizeof(char) * size * 2);
memset(buf, '\0', size);
memset(str, '\0', size * 2);
int i,numread, j;
if ((fp = fopen("/sdcard/cm.yuv", "rb")) != NULL)
{
LOGI("open file success!!");
numread = fread(buf, sizeof(char), size, fp);
LOGI("fread num = %d", numread);
for (i = 0; i < numread; ++i)
{
unsigned char tmp = (unsigned char)buf[i];
sprintf(str + 2 * i, "%x", (tmp & 0xF0) >> 4);
sprintf(str + 2 * i + 1, "%x", (tmp & 0x0F));
}
LOGI("str : %s", str);
}
else
{
LOGI("open file fail!");
}
free(buf);
free(str);
fclose(fp);
}
方法二
void printData(void* data, const int size, const char * name)
{
char * dt = (char *)data;
int i,j;
char * str = (char *) malloc(size * sizeof(char) * 2);
memset(str, '\0', size * sizeof(char) * 2);
for (i = 0; i < size; i++)
{
sprintf(str + 2 * i,"%02x", dt[i]);
}
LOGI_EU("%s , %s", name, str);
free(str);
}
学习到更好的办法再补充