I’m doing some bitshifting work in C, and I’m reading in unsigned char’s. Does every function I use with those variables need to take in an unsigned char as input, or because I loaded the value as unsigned will it automatically keep the first bit positive?
Essentially do I need to do:
int Test1(unsigned char input1)
{
...
}
for everything, or will:
int Test2(char input2)
{
...
}
suffice? Thanks.
int Test2(char input2)might not work. As largestunsigned charis greater than largestsigned char(largest positive integer in the range).But!
Since both
unsigned charandsigned charare of same size, whether you read it assigned charorunsigned charwhat is stored in the memory is the same. Only the interpretation is different when you access them.Also
char vardoes not mean that it is asigned char. It actually depends on compiler flags. Read here.