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 398 views
398 views asked Aug 24, 2021 by avibootz
1 answer 238 views
1 answer 309 views
1 answer 255 views
2 answers 312 views
1 answer 213 views
213 views asked Aug 24, 2021 by avibootz
...