Navigointi
Etusivu
PhpSysInfo
~sami/
Blogi
vnstat
Ladattavaa
Virityksiä
Muuta
Linkkejä
Monsujen tappopeli
Vieraskirja
Chat
|
|
Minimalistinen HEXDUMP-ohjelma
#include <stdio.h>
#define COLS 0x10
char halfbyte2base16(unsigned char hbyte) { if(hbyte < 0xA) return hbyte + 0x30; else return hbyte - 0xA + 0x41; }
char *byte2base16(unsigned char byte) { static char retval[3] = { 0, 0, 0 };
retval[0] = halfbyte2base16(byte >> 4); retval[1] = halfbyte2base16(byte & 0xF);
return retval; }
void printhex(char *str) { putchar(str[0]); putchar(str[1]); }
void printtab(void) { unsigned n; for(n=4;--n;) putchar(' '); }
void printrow() { static unsigned row = 0;
printhex(byte2base16(row >> 8)); printhex(byte2base16(row)); printtab(); row++; }
int main(int argc, char **argv) { int c; unsigned col = 0; unsigned row = 0; char stringified[COLS+1]; FILE *readfp = stdin;
if(argc == 2) { readfp = fopen(argv[1], "rb"); if(!readfp) { puts("Could not open file"); return 1; } }
while((c = fgetc(readfp)) != EOF) { if(!col) printrow();
printhex(byte2base16(c)); if(c >= 0x20 && c < 0x7E) stringified[col] = c; else stringified[col] = '.';
if(++col == COLS) { endrow: stringified[col] = 0; printtab(); puts(stringified); col = 0; }
else putchar(' ');
if(col == COLS >> 1) putchar(' ');
}
if(col) goto endrow;
return 0; }
|
|
|
05:06:18 up 38 days, 7:48, 2 users, load average: 0.23, 0.20, 0.18
total used free shared buff/cache available
Mem: 493 120 119 3 253 356
Swap: 486 126 360