Barbie John
Barbie John

Reputation: 3

I'm starting to use or learn c language

Write a program that uses two dimensional of 256x8 to store 8 bit binary representation of each of the character of ASCII character set

I didn't understand this question properly. Should I have to use 2d array? And place 256 characters on them.. give me some advised or help me sort out to this problem

Upvotes: 0

Views: 57

Answers (1)

Ayan Bhunia
Ayan Bhunia

Reputation: 549

Your question asked you to store the binary representation of all ASCII characters in an array.

As every ASCII character is 8 bit long you need 8 places(ex. int or bool) for each 256 elements total 256*8 2D array.

You can declare the array as,

int codes[256][8];

Now for ASCII of 'a' is 97(dec) or 01100001(bin).

codes[96][0]=0;
codes[96][1]=1;
codes[96][2]=1;
codes[96][3]=0;
codes[96][4]=0;
codes[96][5]=0;
codes[96][6]=0;
codes[96][7]=1;

You can print the binary representation as,

for(int i=0;i<8;i++)
    printf("%d",codes['a'][i]);

Upvotes: 1

Related Questions