Converting an unsigned short or int to a char
Posted on 2003-11-11
I'm trying to write this large program and a small part of it requires me to perform bitwise operations such as masking. Unfortunately what I must work with is a character array, and I must mask it with an unsigned short array or int.
Suppose I'm working with a short.
unsigned short x = 32768; //1000000000000000 in binary
Since short is 16 bits and char is 8 bits, i tried to shift x to the right 8 bits so...
x = x >> 8;
p = x; //this doesn't seem to work, i've tried other types of casting on this also.
otherFunction(p); //otherFunction requires that I pass in a char*
Also note I'm working with a bit mapping assignment.