In questo articolo vedremo i diversi modi di rappresentare un byte, esattamente in ASCII, Esadecimale, Decimale, Ottale, Binario.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void dispword(char *str) {
int bit, i;
unsigned char chr;
printf("Ch Hx Dec Oct Binary\n"
"----------------------\n");
i = 0;
while((chr = str[i]) != NULL) {
printf(" %c %02x %03d %03o ",
chr, chr, chr, chr);
bit = 0x80;
do {
if(chr & bit) fputc('1', stdout);
else fputc('0', stdout);
bit >>= 1;
} while(bit);
fputc('\n', stdout);
i++;
}
return(0);
}