Hello guys.I need to write a program that "transforms" the input array into a binary code.So far, so great.My only problem is that I know how to make it show the decimal code, I can't figure out how to make it "transform" into binary .. can you guys help ? I've written a comment to the matching line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<iostream>
#include<string.h>
#include<math.h>
usingnamespace std;
int main()
{
char bin[50];
cout<<"Input the array : ";
cin>>bin;
cin.ignore(1);
int number=0;
int p=strlen(bin)-1;
for(int i=p;i>=0;i--)
number+=(bin[i]-48)*(int)pow(2,(p-i)); //The only problematic line.
cout<<number<<endl;
system("pause");
return 0;
}