int a = 4, b = 7, c = 5;
int x = (c << 16) | (b << 8) | a);
a = (x >> 0 ) & 0xff;
b = (x >> 8) & 0x00ff;
c = (x >> 16) & 0x0000ffff;
struct BitField{
union{
int value;
struct{
int a:8;
int b:8;
int c:16;
};
};
};
BitField MyBits;
MyBits.a = 4; //fill the internal bit structure
MyBits.b = 7;
MyBits.c = 5;
cout << MyBits.value; //print the full int representation
int8_t a = 4, b = 7, c = 6;
int32_t x = (c << 16) | (b << 8) | a;
// извлекаем:
a = (x & 0x000000FF);
b = (x & 0x0000FF00) >> 8;
c = (x & 0x00FF0000) >> 16;
a = x & 0xFF;
if (a & 0x80)
a &= -1;