#include <iostream>
using namespace std;
struct encoder {
uint32_t val;
encoder(uint32_t _val = 0) : val(_val) {}
uint32_t first(uint32_t v = 0) {
if (!v) return (val << (8*3)) >> (8*3);
val |= v;
}
uint32_t second(uint32_t v = 0) {
if (!v) return (val << (8*2)) >> (8*3);
encoder _backupval(val);
val = (val >> (8*1));
val |= v;
val = (val << (8*1));
val |= _backupval.first();
return val;
}
uint32_t third(uint32_t v = 0) {
if (!v) return (val << (8*1)) >> (8*3);
encoder _backupval(val);
val = (val >> (8*2));
val |= v;
//now restore
val = val << 8;
val |= _backupval.second();
val = val << 8;
val |= _backupval.first();
return val;
}
uint32_t fourth(uint32_t v = 0) {
if (!v) return (val << (8*0)) >> (8*3);
encoder _backupval(val);
val = (val >> (8*3));
val |= v;
//now restore
val = val << 8;
val |= _backupval.third();
val = val << 8;
val |= _backupval.second();
val = val << 8;
val |= _backupval.first();
}
};
int main() {
encoder t;
t.first(6);
t.second(42);
t.third(212);
t.fourth(23);
cout << "first number: " << t.first()
<< "\nsecond number: " << t.second()
<< "\nthird number: " << t.third()
<< "\nfourth number: " << t.fourth() << endl;
}