How to convert binary to decimal in C++

1 Answer

0 votes
#include <iostream>
#include <bitset>

int main(void) {
    std::string binary = "11111101";
    unsigned long decimal = std::bitset<8>(binary).to_ulong();
    
    std::cout << decimal;
}



  
/*
run:
   
253
   
*/

 



answered Aug 24, 2021 by avibootz
edited Feb 28, 2022 by avibootz

Related questions

2 answers 296 views
2 answers 399 views
399 views asked Aug 24, 2021 by avibootz
1 answer 239 views
1 answer 310 views
1 answer 256 views
2 answers 314 views
1 answer 214 views
214 views asked Aug 24, 2021 by avibootz
...