Unsigned Integer to BCD conversion?

前端 未结 10 1390
囚心锁ツ
囚心锁ツ 2020-12-11 05:01

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

10条回答
  •  天命终不由人
    2020-12-11 05:17

    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 >();
    }
    

提交回复
热议问题