__ >(' ) )/ /( / `----/ \ ~=- / ~^~^~^~^~^~^~^
#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;}
09:31:23 up 202 days, 11:12, 0 users, load average: 0.04, 0.02, 0.00 total used free shared buff/cache available Mem: 493 125 80 3 288 352 Swap: 486 141 345
Sivun generointi kesti 0.49 s