#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
usingnamespace std;
string m[6];string ye;ostringstream wa;
string momo;
//pass function result to main
void con(int n)
{
int a,i,j; int o=0;
int b[6];
for(i=0;n!=0;i++)//get the number of digits(i)and number on digit(b[i])
{
a=n%16; //remainder,which is the right most digit;
b[i]=a; //b[0]=right most digit,b[1]=second digit...
n=n/16; //the quotient used for the next iteration unless it is equal to 0, then there will be no more iteration.
}
for(j=i-1;j>=0;j--)//the loop to print out array
{
if(b[j]==10)
{
m[o]="A";
}
elseif(b[j]==11)
{
m[o]="B";
}
elseif(b[j]==12)
{
m[o]="C";
}
elseif(b[j]==13)
{
m[o]="D";
}
elseif(b[j]==14)
{
}
elseif(b[j]==15)
{
}
else
{
m[o]=b[j] +'0';
}
wa<< m[o];
o++;
}
}
void addhex(hex[],hex[]){
}
int main(){
int x,y;
string ha[];int hb[];
cout<<"Enter 2 integers:"<<endl;
cin>>x>>y;
con(x);
cout<<"The first number is"<<setw(6) << setfill('0')<< wa.str()<<endl;
wa.str
wa.str().clear();
con(y);
cout<<"The second number is"<<setw(6) << setfill('0')<< wa.str()<<endl;
addhex(ha[],hb[]);
return 0;
}
1)What should be the best variable for adding two 6-digit hexadecimal,such as 0034AD,0057EA? I would like to use array of character but it seems hard to handle.
"similar to adding two decimal numbers, except that a carry will be generated if the sum is > 16, instead of 10. You start from the rightmost digit, add the digits together. If the result is greater than 16, and there is a carry and you subtract from the result by 16. "