I have 2 chars: HIGH and LOW and I’d like to convert them to an int corresponding to HIGH + the 2 left bits from LOW.
I tried somethine like :
unsigned char high;
unsigned char low;
high = 128; // 10000000
low= 128; // 10000000
int result; (should be high 10000000 + 2 left bites of low 10 = 1000000010)
// To do
return result;
Edited for more clarity.
The solution I chosed is:
return high*4 + (low >> (CHAR_BIT - 2));
You declare
HIGHandLOWaschar*, but you don’t use them as pointer. The following code works fine (BTW, avoid upper case identifiers when you don’t use constants):This is how I understand your question (it could be more understandable):