Answer to Question #198915 in C for Nabeel khan

Question #198915

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.


1
Expert's answer
2021-05-26T10:38:07-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS