drankinatty

ASCII Chart - 4 Column Char, Dec, Oct, Hex

Sep 24th, 2021
1,112
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. enum { TWO = 1u << 1, R1 = 1u << 5, R2 = 1u << 6, R3 = R1 + R2 };
  4.  
  5. int main (void) {
  6.  
  7.     /* non-printing characters */
  8.     char *special[] = { "(nul)", "(soh)", "(stx)", "(etx)",
  9.                         "(eot)", "(enq)", "(ack)", "(bel)",
  10.                         "(bs)",  "(ht)",  "(nl)",  "(vt)",
  11.                         "(np)",  "(cr)",  "(so)",  "(si)",
  12.                         "(dle)", "(dc1)", "(dc2)", "(dc3)",
  13.                         "(dc4)", "(nak)", "(syn)", "(etb)",
  14.                         "(can)", "(em)",  "(sub)", "(esc)",
  15.                         "(fs)",  "(gs)",  "(rs)",  "(us)",
  16.                         "(sp)",  "(del)" };
  17.  
  18.     /* print heading */
  19.     printf ("Char  Dec  Oct  Hex | Char  Dec  Oct  Hex | "
  20.             "Char  Dec  Oct  Hex | Char  Dec  Oct  Hex\n"
  21.             "--------------------------------------------"
  22.             "-----------------------------------------\n");
  23.  
  24.     /* print chars */
  25.     for (unsigned i = 0; i < R1; i++) {
  26.         char s1[TWO] = { (char)i+R1, 0 },
  27.              s2[TWO] = { (char)i+R2, 0 },
  28.              s3[TWO] = { (char)i+R3, 0 };
  29.  
  30.         printf ("%-5s %3d %04o 0x%02x | %-5s %3d %04o 0x%02x | "
  31.                 "%-5s %3d %04o 0x%02x | %-5s %3d %04o 0x%02x\n",
  32.                 special[i], i, i, i,
  33.                 i ? s1 : special[R1], i+R1, i+R1, i+R1,
  34.                 s2, i+R2, i+R2, i+R2,
  35.                 i == R1 - 1 ? special[R1+1] : s3, i+R3, i+R3, i+R3);
  36.     }
  37.  
  38.     return 0;
  39. }
  40.  
RAW Paste Data