A simple C function to print binary data
13.02.2013 [Software]
This is one of those generic functions that I use in practically all my reversing projects. The first argument is an adress in memory and the second argument specifies the number of bytes to show.
#include <inttypes.h>
void printHex(const void *lpvbits, const unsigned int n) {
    char* data = (char*) lpvbits;
    unsigned int i = 0;
    char line[17] = {};
    printf("%016" PRIXPTR " | ", (uintptr_t)data);
    while ( i < n ) {
        line[i%16] = *(data+i);
        if ((line[i%16] < 32) || (line[i%16] > 126)) {
            line[i%16] = '.';
        }
        printf("%.2X", (unsigned char)*(data+i));
        i++;
        if (i%4 == 0) {
            if (i%16 == 0) {
                if (i < n-1)
                    printf(" | %s\n%016" PRIXPTR " | ", (char*)&line, (uintptr_t)data+i);
            } else {
                printf(" ");
            }
        }
    }
    while (i%16 > 0) {
        (i%4 == 0) ? printf("   ") : printf("  ");
        line[i%16] = ' ';
        i++;
    }
    printf(" | %s\n", (char*)&line);
}
Example output
003621C8 | 40106403 501D3F01 10106403 30106403 | @.d.P.?...d.0.d.
003621D8 | 20106403 00000000 00000000 00000000 | ..d.............
003621E8 | 00000000 00000000 00000000 7808B003 | ............x...
003621F8 | A009B003 C80AB003 D019B003 F81AB003 | ................
00362208 | 201CB003 481DB003 701EB003 00000000 |  ...H...p.......
00362218 | 00000000 00000000 00000000 00000000 | ................