Ankkaserver


    __
  >(' )
    )/
    /(
   /  `----/
   \  ~=- /
 ~^~^~^~^~^~^~^

Navigointi
Etusivu
PhpSysInfo
~sami/
Blogi
vnstat
Ladattavaa
Virityksiä
Muuta
Linkkejä
Monsujen tappopeli
Vieraskirja
Chat

Ota SSL käyttöön

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((= fgetc(readfp)) != EOF)
  {
    if(!col)
      printrow();

    printhex(byte2base16(c));
    if(>= 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;
}

 17:58:28 up 108 days,  1:47,  2 users,  load average: 0.11, 0.08, 0.01
               total        used        free      shared  buff/cache   available
Mem:             493         138          41           7         313         334
Swap:            486         148         338

Valid HTML 4.01 Strict Valid CSS!

http://sininenankka.dy.fi
http://lfnoajc2cqttvkgx.onion
Tietoja ylläpitäjästä

Sivun generointi kesti 0.496 s