I have trouble with figuring out how to put 9 char into an array of 4 unsigned short in c programming.
I know that a char is 1 byte, but only 7 bits are used because ascii table are 0 ~ 127, so I need 7 * 9 = 63 bits. since short is 2 bytes each, then it has 16 bits for each short. array of 4 short is 4 * 16 = 64 bits. Which means that I can fit those 9 char into an array of 4 unsigned short
so basically I have
unsigned short *ptr, theArray[4], letter = 0;
int mask;
//read 9 char and save it to the array
What I don't understand is how to read the 4 characters input and save it to theArray. The limitation is that I can't put them into a string first, I can't declare anything else except int. I know I have to do some bit manipulation, but I just don't know how to read the input. Thank you for your help!
charin bits and that ofshortin bytes. Finally, what have you tried? - user529758