convert binary to decimal c++ stl
string bin_string = "10101010";
int number =0;
number = stoi(bin_string, 0, 2);
// number = 170
                                
                            convert binary to decimal c++ stl
string bin_string = "10101010";
int number =0;
number = stoi(bin_string, 0, 2);
// number = 170
                                
                            convert decimal to binary in c++
// C++ program to convert a decimal 
// number to binary number 
  
#include <iostream> 
using namespace std; 
  
// function to convert decimal to binary 
void decToBinary(int n) 
{ 
    // array to store binary number 
    int binaryNum[32]; 
  
    // counter for binary array 
    int i = 0; 
    while (n > 0) { 
  
        // storing remainder in binary array 
        binaryNum[i] = n % 2; 
        n = n / 2; 
        i++; 
    } 
  
    // printing binary array in reverse order 
    for (int j = i - 1; j >= 0; j--) 
        cout << binaryNum[j]; 
} 
  
// Driver program to test above function 
int main() 
{ 
    int n = 17; 
    decToBinary(n); 
    return 0; 
}
                                
                            convert decimal to binary c++
- Convert decimal to binary string using std::bitset
int n = 10000;
string s = bitset<32>(n).to_string(); // 32 is size of n (int)
                                
                            how to do decimal to binary converdsion in c++
// C++ program for decimal to binary 
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std; 
int main() {
    vector<int>nums; // list that will hold binary values
    int num = 0; 
    cout<<"Number: "<<endl;
    cin>>num; // number input 
    int i=0; // iterator for vector
    while(num!=0)
    {
        nums.push_back(num%2); // adds binary value to the back of string 
        i++; // i gets incremented for the next position in vector 
        num=num/2; 
    }
 
    reverse(nums.begin(),nums.end()); // reverses order of vector 
  
    for(auto x:nums)
    {
        cout<<x; // outputs stuff in vector 
    }
  return 0; 
}
                                
                            Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us