Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
=================================================================================================
int main()
{
unsigned int value;
int str_len;
char selection[64];
char input_string[64];
int done = 0;
while(!done)
{
cout<<"(b) - enter a binary value\n"
"(d) - enter a decimal value\n"
"(h) - enter a hex value\n"
"(o) - enter an octal value\n"
"(q) - to quit\n"
"Selection: ";
//cin.getline(selection,63);
cin>>selection;
switch(*selection)
{
case 'b':
cout<<"Enter your binary value: ";
cin>>input_string;
str_len = strspn(input_string,"01");
if(strlen(input_string)!=str_len)
{
cerr<<"Invalid Binary String Entered\n";
continue;
}
else
{
value = 0;
for(int i=0,j=str_len-1;i<str_len;i++,j--)
if(input_string[i] == '1')
value |= 1<<j;
}
break;
case 'd':
cout<<"Enter your decimal value: ";
cin>>dec>>value;
break;
case 'h':
cout<<"Enter your hex value: ";
cin>>hex>>value;
break;
case 'o':
cout<<"Enter your octal value: ";
cin>>oct>>value;
break;
case 'q':
done = 1;
continue;
break;
default:
cerr<<"invalid choice!\n\n";
continue;
break;
}
bin_struct bin_out;
bin_out = value;
cout<<"\n******************************************\n";
cout<<"Binary: "<<bin_out<<endl;
cout<<"Decimal: "<<dec<<value<<endl;
cout<<"Hex: "<<hex<<value<<endl;
cout<<"Octal: "<<oct<<value<<endl;
cout<<"******************************************\n";
}
return 0;
disregard the binstruct stuff. The basics of what you need are there.