Write a program that uses a two dimensional of 256 x 8 to store 8 bit binary representations of each of the characters of ASCII character set.
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#define CHARSET 256
#define BITS 8
int main() {
int table[CHARSET][BITS] = {0};
for (size_t i = 0; i != CHARSET; i++) {
unsigned char value = (unsigned char)i;
size_t j = BITS - 1;
while (value) {
table[i][j] = value & 1;
value >>= 1;
j--;
}
}
for (size_t i = 0; i != CHARSET; i++) {
for (size_t j = 0; j != BITS; j++) {
printf("%d", table[i][j]);
}
printf("\n");
}
return 0;
}
Comments
Leave a comment