
number conversion help
I am trying to make a program to change the base of numbers from base 10 to anything they want (from 236). the problem arises when i am trying to convert the numbers to a hex format. I have no clue where i should go, the code i have written so far is
Code:
void convert(vector<int>& rev_rems,int base,int num_div,vector<int>& rems)
{
int num;
int rem;
for(num=num_div;num!=0;num/=base)
{
rem=num%base;
rev_rems.push_back(rem);
}
for(rev_rems;rev_rems.size()!=0;rev_rems.pop_back())
{
rems.push_back(rev_rems[rev_rems.size()1]);
}
}
void hex_convert(vector<int>& rems,vector<int>& rev_hex)
{
for(int hex=rems[rems.size()1];rems.size()!=0;rems.pop_back())
{
hex=hex10;
if(hex<0)
{rev_hex.push_back(rems[rems.size()1]);}
else
{rev_hex.push_back('0'+hex);}
}
}
the converting part works fine, its the hex_convert where i get confused on what to do

Why can't you just call convert from hex_convert?

i could, however, i want to know how to convert it to the hex format before i condense them down, easier to follow what im doing, and then this way i can check to make sure that the answers i'm getting when i do the first conversion are still correct

Then look at your hex_convert code and ask yourself "What was I on when I wrote this?"
What does subtracting 10 have to do with converting to hex? Why are you always pushing the last digit of your original into your answer? Why is '0' involved? Where is the number 16?

the 10 comes in from the fact that there are 10 single digit numbers (09), then the double digit numbers (1099), at 10 is when the program would start using letters, A=10, B=11, etc., however to advance the count i need to be able to add the the values of A,B,C etc, starting at 65 which is A, if you were to add 10 to 65 it come up as 75!=A but ==J, so the 10 is there to keep the location of the number associated with the letters correct, otherwise i would skip the first 9 letters of the alphabet and jump straight to J.
The '0' was me trying to play around and figure out how to get the letters to show instead of numbers.
as to the question u posed about the number 16, i dont understanding what you are asking about it

So you have to decide whether the elements in your vector are the characters '0' through '9', 'A' through 'F', or the numbers 0 through 15. (Hint: whoever wrote the first convert function assumed the latter.) For instance: if you subtract 10 from any of the characters '0' through '9', 'A' through 'F' you will not get anywhere near the number 0. If you subtract 10 from the real numbers themselves, it would make sense to check against 0; but in that case it didn't make sense to subtract 10 in the first place, since you already have the real value of the number.
I am still very interested in how you intend to convert to base 16 without ever including the number 16 in your code.

I must apologize for wasting your time just now, i just realized that i am trying to use the character value references for calling the letters. A=65 to Z=90, i am NOT trying to convert to hex, this was a huge blind sight on my part, basically what i am trying to do is similar to hex, but only use the rest of the alphabet if it is needed.
What i am trying to do is converting from dec code into char code