#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <iomanip>
using namespace std;
class MyBinary {
private:
static const unsigned _BIT_LEN = 1024;
const int _digits;
int _len;
bitset<_BIT_LEN> _acc;
public:
MyBinary(int digits) : _digits(digits), _len(5), _acc(digits) {}
void add(unsigned long val) {
_len += _digits;
_acc <<= _digits;
for (int i(0); i<_digits; i++)
_acc.set(i, val & (1U << i));
}
vector<string> get_bit_strings(int offset) {
string src(_acc.to_string().substr(_BIT_LEN - _len));
vector<string> dst;
for (int i(0); i<_len; i+=offset) {
if (i < _len-offset)
dst.push_back(src.substr(i, offset));
else {
string tmp(src.substr(i, offset - (_len - i)));
tmp.append(_len - i, '0');
dst.push_back(tmp);
}
}
return dst;
}
};
int main()
{
MyBinary mb(6);
mb.add(0);
mb.add(20);
mb.add(0);
mb.add(20);
vector<string> vs(mb.get_bit_strings(8));
for (int i(0); i<vs.size(); i++)
cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << bitset<8>(vs.at(i)).to_ulong() << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Yml0c2V0PgojaW5jbHVkZSA8aW9tYW5pcD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKY2xhc3MgTXlCaW5hcnkgewogIHByaXZhdGU6CiAgICBzdGF0aWMgY29uc3QgdW5zaWduZWQgX0JJVF9MRU4gPSAxMDI0OwoKICAgIGNvbnN0IGludCAgICAgICAgIF9kaWdpdHM7CiAgICBpbnQgICAgICAgICAgICAgICBfbGVuOwogICAgYml0c2V0PF9CSVRfTEVOPiAgX2FjYzsKIAogIHB1YmxpYzoKICAgIE15QmluYXJ5KGludCBkaWdpdHMpIDogX2RpZ2l0cyhkaWdpdHMpLCBfbGVuKDUpLCBfYWNjKGRpZ2l0cykge30KIAogICAgdm9pZCBhZGQodW5zaWduZWQgbG9uZyB2YWwpIHsKICA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