C++ - Decimal to binary converting

后端 未结 29 3644
一向
一向 2020-11-28 18:53

I wrote a \'simple\' (it took me 30 minutes) program that converts decimal number to binary. I am SURE that there\'s a lot simpler way so can you show me? Here\'s the code:<

29条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 19:51

    You can use std::bitset to convert a number to its binary format.

    Use the following code snippet:

    std::string binary = std::bitset<8>(n).to_string();
    

    I found this on stackoverflow itself. I am attaching the link.

提交回复
热议问题