How to convert int to binary with leading zeros in C++

1 Answer

0 votes
#include <iostream>
#include <bitset>
 
int main()
{
    unsigned int num = 153;
    
    std::string binary = std::bitset<16>(num).to_string(); 
    
    std::cout << binary;
}
 
   
   
   
/*
run:
   
0000000010011001
   
*/

 



answered Jan 7, 2024 by avibootz

Related questions

1 answer 142 views
1 answer 207 views
1 answer 221 views
1 answer 293 views
1 answer 229 views
1 answer 208 views
1 answer 154 views
...