C语言 HexDump

#include 

// 内存查看
void hexDump(const unsigned char *data, size_t size)
{
     
    int i;
    size_t offset = 0;
    while (offset < size)
    {
     
        printf("%04x  ", offset);
        for (i=0; i<16; i++)
        {
     
            if (i%8 == 0) putchar(' ');
            if (offset+i < size)
            {
     
                printf("%02x ", data[offset + i]);
            }
            else
            {
     
                printf("   ");
            }
        }
		printf("   ");
        for (i=0; i<16 && offset+i<size; i++)
        {
     
            if (isprint(data[offset+i]))
            {
     
                printf("%c", data[offset+i]);
            }
            else
            {
     
                putchar('.');
            }
        }
        putchar('\n');
        offset += 16;
    }
}

你可能感兴趣的:(Windows编程)