#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <string>
using namespace std;
int dectoint (string st);
int hextoint (string st);
int bintoint (string st);
string inttobin (int n);
string inttohex (int n);
int main()
{
string st;
cout<< "Enter a number in dec,hex,or binary: \n";
getline(cin,st);
if (st[0]=='$')
cout << st<< "=" << hextoint(st)<<", "<< st <<", "<< inttobin(hextoint(st))<<endl;
/*else if(st[0]=='%')
cout << st<< "=" << inttohex(bintoint(st))<<", "<< inttohex((bintoint(st))<< ", "<<st<< endl;
else if(st[0]!='$' && st[0]!='%')
cout << st<< "=" << inttohex(st)<< ", "<<inttobin(st)<<endl;
*/
return 0;
}
int dectoint(string st)
{
int n=0;
for (int i=0; i<st.length(); i++)
{
char ch = st [i];
n= n*10+(ch-'0');
}
return n;
}
int hextoint (string st)
{
int n=0;
for (int i=1; i<st.length(); i++)
{
char ch= st[i];
n= n*16+(ch-'0');
}
return n;
}
int bintoint (string st)
{
int n=0;
for (int i=1; i<st.length(); i++)
{
char ch= st[i];
n= n*2+(ch-'0');
}
return n;
}
string inttobin (int n)
{
ostringstream buffer;
string result=buffer.str();
int num;
while (n>0)
{
num=n%2;
if (n>1)buffer<< num;
else if (n ==1) buffer<<n;
n=n/2;
}
return result;
}
/*string inttohex (int n)
{
ostringstream buffer;
string result=buffer.str();
int num;
while (n>=0)
{
num=n%16;
buffer<<num='0';
n=n/16;
}
return result;
}*/
When ran I enter $13 and get:
$13=19, $13,
In the blank space after the last comma, it should have SOMETHING at least im hoping for 1101 ????