Binary to decimal conversion

i want to store 00110 in my array ,which data type i will take so that this number stores correctly and convert into decimal no?

Hi @amishakumari

You can take input of number in a string and traverse the string from right to left and if that digit is 1 then add 2^index tot he total where index is zero for the rightmost element of string.

Code for reference : //As ide is not working so i pasted the code here

#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
string s;
while(n–)
{
cin>>s;
int le = s.size();
int cnt = 0;
int tot = 0;
for(int i=le-1;i>=0;i–)
{
if(s[i]==ā€˜1’)
{
tot+= (1<<cnt);
}
cnt++;
}
cout<<tot<<"\n";
}
return 0;
}
Hope it Helps.