Skip to content

Instantly share code, notes, and snippets.

@mgold
Created August 5, 2013 20:14
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/6159177 to your computer and use it in GitHub Desktop.
Save mgold/6159177 to your computer and use it in GitHub Desktop.
Translates hexidecimal digits into ASCII art, with the brightness correlated to the magnitude of the digit. The input may be either ASCII hex (either upper or lowercase) digits or machine values. Try it on random data, or the compiled executable of the program (and vary your terminal width). An octal version is also available.
/* hexBright.c - visualize hex data with brightness
* Max Goldstein
*
* example usage:
* $ head /dev/urandom | hexdump -e '16/1 "%02x " "\n"' | ./hexBright
*/
#include <stdio.h>
int main(){
while(1){
int c = getchar();
if (c == EOF){
break;
}else if (c >= '0' && c <= '9'){
c -= '0';
}else if (c >= 'A' && c <= 'F'){
c -= 'A';
}else if (c >= 'a' && c <= 'f'){
c -= 'a';
}else{
continue;
}
putchar(" .:;-~=+a*&$#%M@"[c]);
}
putchar('\n');
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment