I know you can use this table to convert decimal to BCD:
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 01
Would something like this work for your conversion?
#include #include using namespace std; string dec_to_bin(unsigned long n) { return bitset::digits>(n).to_string, allocator >(); }