Skip to content

Instantly share code, notes, and snippets.

@mgold
Last active December 20, 2015 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgold/6158168 to your computer and use it in GitHub Desktop.
Save mgold/6158168 to your computer and use it in GitHub Desktop.
Translates octal digits into ASCII art, with the brightness correlated to the magnitude of the digit. The input may be either ASCII octal digits or machine octal. Try it on random data, or the compiled executable of the program (and vary your terminal width). A hexidecimal version is also available.
/* octBright.c - visualize octal data with brightness
* Max Goldstein
*
* example usage:
* $ od -o < /dev/random | sed 's/^[0-9]* +//' | tr -d ' ' | ./octBright
*/
#include <stdio.h>
int main(){
while(1){
int c = getchar();
if (c == EOF){
break;
}
if (c >= '0' && c <= '7'){
c -= '0';
}
if (c >= 0 && c <= 7){
putchar(".-~:;#$@"[c]);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment