convert binary string to decimal c++ code example
Example 1: convert binary to decimal c++ stl
string bin_string = "10101010";
int number =0;
number = stoi(bin_string, 0, 2);
Example 2: how to do decimal to binary converdsion in c++
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<int>nums;
int num = 0;
cout<<"Number: "<<endl;
cin>>num;
int i=0;
while(num!=0)
{
nums.push_back(num%2);
i++;
num=num/2;
}
reverse(nums.begin(),nums.end());
for(auto x:nums)
{
cout<<x;
}
return 0;
}