How to use built in function to convert binary to decimal in C++

2 Answers

0 votes
#include <iostream>
#include <bitset>
 
int main(void) {
    std::string binary = "11110101";
    unsigned long decimal = std::bitset<8>(binary).to_ulong();
     
    std::cout << decimal;
}
 
 
 
   
/*
run:
    
245
    
*/

 



answered Feb 28, 2022 by avibootz
0 votes
#include <iostream>
#include <bitset>
 
int main(void) {
    std::bitset<8> bits("11110101");
    
    unsigned long decimal= bits.to_ulong();
     
    std::cout << decimal;
}
 
 
 
   
/*
run:
    
245
    
*/

 



answered Feb 28, 2022 by avibootz

Related questions

1 answer 99 views
99 views asked Aug 24, 2021 by avibootz
2 answers 150 views
150 views asked Aug 24, 2021 by avibootz
1 answer 117 views
1 answer 162 views
1 answer 118 views
2 answers 144 views
2 answers 144 views
...