#include <iostream>
#include <cstdint>
using namespace std;
int32_t encode(int32_t a, int32_t b, int32_t c, int32_t d) {
return (a << 12) + (b << 8) + (c << 4) + d;
}
void decode(int32_t value, int32_t *result) {
const int32_t mask = 0xf;
result[0] = (value >> 12) & mask; // a
result[1] = (value >> 8) & mask; // b
result[2] = (value >> 4) & mask; // c
result[3] = value & mask; // d
}
int main() {
int32_t result[] = {0, 0, 0, 0};
int32_t encoded = encode(6, 4, 2, 9);
decode(encoded, result);
cout << "a: " << result[0] << endl
<< "b: " << result[1] << endl
<< "c: " << result[2] << endl
<< "d: " << result[3] << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGludD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludDMyX3QgZW5jb2RlKGludDMyX3QgYSwgaW50MzJfdCBiLCBpbnQzMl90IGMsIGludDMyX3QgZCkgewoJcmV0dXJuIChhIDw8IDEyKSArIChiIDw8IDgpICsgKGMgPDwgNCkgKyBkOwp9Cgp2b2lkIGRlY29kZShpbnQzMl90IHZhbHVlLCBpbnQzMl90ICpyZXN1bHQpIHsKCWNvbnN0IGludDMyX3QgbWFzayA9IDB4ZjsKCXJlc3VsdFswXSA9ICh2YWx1ZSA+PiAxMikgJiBtYXNrOyAvLyBhCglyZXN1bHRbMV0gPSAodmFsdWUgPj4gOCkgJiBtYXNrOyAvLyBiCglyZXN1bHRbMl0gPSAodmFsdWUgPj4gNCkgJiBtYXNrOyAvLyBjCglyZXN1bHRbM10gPSB2YWx1ZSAmIG1hc2s7IC8vIGQKfQoKaW50IG1haW4oKSB7CglpbnQzMl90IHJlc3VsdFtdID0gezAsIDAsIDAsIDB9OwoJCglpbnQzMl90IGVuY29kZWQgPSBlbmNvZGUoNiwgNCwgMiwgOSk7CglkZWNvZGUoZW5jb2RlZCwgcmVzdWx0KTsKCQoJY291dCA8PCAiYTogIiA8PCByZXN1bHRbMF0gPDwgZW5kbAoJCTw8ICJiOiAiIDw8IHJlc3VsdFsxXSA8PCBlbmRsCgkJPDwgImM6ICIgPDwgcmVzdWx0WzJdIDw8IGVuZGwKCQk8PCAiZDogIiA8PCByZXN1bHRbM10gPDwgZW5kbDsKCQoJcmV0dXJuIDA7Cn0=