Convert 2 char into 1 int

Posted by Leo on Stack Overflow See other posts from Stack Overflow or by Leo
Published on 2012-12-15T16:56:19Z Indexed on 2012/12/15 17:03 UTC
Read the original article Hit count: 152

Filed under:
|
|
|

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 :

char *HIGH;
char *LOW;
HIGH = 152;
LOW = 12;
int result;
result += (LOW + 6);
result += (LOW + 7)*2;
result += HIGH*4;
result += (HIGH + 1)*8;
result += (HIGH + 2)*16;
result += (HIGH + 3)*32;
result += (HIGH + 4)*64;
result += (HIGH + 5)*128;
result += (HIGH + 6)*256;
result += (HIGH + 7)*512;
return result;

But it doesn't work and I don't understand why.

© Stack Overflow or respective owner

Related posts about c

    Related posts about casting