I am making a cd key replacer that will input the new cd key, change the key into base 24 then hex, and put the key into the registry. I am trying to figure out how to go from decimal to base 24 (I go to binary along the way). The numbers here are inputted as hex with a comma and no spaces after each value. At the point where I output values (at the bottom of my code), regardless of what I plug in, the first four are zero, and the fifth is always 2293672. Any suggestions on how to fix this?

``````int values[119] = {0}, reverse[119] = {0}, z = 15;
int i = 0;
cout << "What number would you like to convert: ";
for(i = 0; i < 15; i++)
{
hex[i][0] = cin.get();
hex[i][1] = cin.get();
cin.ignore(99999, ',');
hexrev[z][0] = hex[i][0];
hexrev[z][1] = hex[i][1];
z--;
}
cout << hexrev[0][0] << hexrev[0][1]
for(i = 0; i < 15; i++)
{
if(hexrev[i][0] == '0')
{
values[4 * i] = 0;
values[4 * i + 1] = 0;
values[4 * i + 2] = 0;
values[4 * i + 3] = 0;
}
else if(hexrev[i][0] == '1')
{
values[4 * i] = 0;
values[4 * i + 1] = 0;
values[4 * i + 2] = 0;
values[4 * i + 3] = 1;
}
else if(hexrev[i][0] == '2')
{
values[4 * i] = 0;
values[4 * i + 1] = 0;
values[4 * i + 2] = 1;
values[4 * i + 3] = 0;
}
else if(hexrev[i][0] == '3')
{
values[4 * i] = 0;
values[4 * i + 1] = 0;
values[4 * i + 2] = 1;
values[4 * i + 3] = 1;
}
else if(hexrev[i][0] == '4')
{
values[4 * i] = 0;
values[4 * i + 1] = 1;
values[4 * i + 2] = 0;
values[4 * i + 3] = 0;
}
else if(hexrev[i][0] == '5')
{
values[4 * i] = 0;
values[4 * i + 1] = 1;
values[4 * i + 2] = 0;
values[4 * i + 3] = 1;
}
else if(hexrev[i][0] == '6')
{
values[4 * i] = 0;
values[4 * i + 1] = 1;
values[4 * i + 2] = 1;
values[4 * i + 3] = 0;
}
else if(hexrev[i][0] == '7')
{
values[4 * i] = 0;
values[4 * i + 1] = 1;
values[4 * i + 2] = 1;
values[4 * i + 3] = 1;
}
else if(hexrev[i][0] == '8')
{
values[4 * i] = 1;
values[4 * i + 1] = 0;
values[4 * i + 2] = 0;
values[4 * i + 3] = 0;
}
else if(hexrev[i][0] == '9')
{
values[4 * i] = 1;
values[4 * i + 1] = 0;
values[4 * i + 2] = 0;
values[4 * i + 3] = 1;
}
else if(hexrev[i][0] == 'A' || hexrev[i][0] == 'a')
{
values[4 * i] = 1;
values[4 * i + 1] = 0;
values[4 * i + 2] = 1;
values[4 * i + 3] = 0;
}
else if(hexrev[i][0] == 'B' || hexrev[i][0] == 'b')
{
values[4 * i] = 1;
values[4 * i + 1] = 0;
values[4 * i + 2] = 1;
values[4 * i + 3] = 1;
}
else if(hexrev[i][0] == 'C' || hexrev[i][0] == 'c')
{
values[4 * i] = 1;
values[4 * i + 1] = 1;
values[4 * i + 2] = 0;
values[4 * i + 3] = 0;
}
else if(hexrev[i][0] == 'D' || hexrev[i][0] == 'd')
{
values[4 * i] = 1;
values[4 * i + 1] = 1;
values[4 * i + 2] = 0;
values[4 * i + 3] = 1;
}
else if(hexrev[i][0] == 'E' || hexrev[i][0] == 'e')
{
values[4 * i] = 1;
values[4 * i + 1] = 1;
values[4 * i + 2] = 1;
values[4 * i + 3] = 0;
}
else if(hexrev[i][0] == 'F' || hexrev[i][0] == 'f')
{
values[4 * i] = 1;
values[4 * i + 1] = 1;
values[4 * i + 2] = 1;
values[4 * i + 3] = 1;
}
else
int q = 4;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
if(hexrev[i][1] == '0')
{
values[4 * i + 4] = 0;
values[4 * i + 5] = 0;
values[4 * i + 6] = 0;
values[4 * i + 7] = 0;
}
else if(hexrev[i][1] == '1')
{
values[4 * i + 4] = 0;
values[4 * i + 5] = 0;
values[4 * i + 6] = 0;
values[4 * i + 7] = 1;
}
else if(hexrev[i][1] == '2')
{
values[4 * i + 4] = 0;
values[4 * i + 5] = 0;
values[4 * i + 6] = 1;
values[4 * i + 7] = 0;
}
else if(hexrev[i][1] == '3')
{
values[4 * i + 4] = 0;
values[4 * i + 5] = 0;
values[4 * i + 6] = 1;
values[4 * i + 7] = 1;
}
else if(hexrev[i][1] == '4')
{
values[4 * i + 4] = 0;
values[4 * i + 5] = 1;
values[4 * i + 6] = 0;
values[4 * i + 7] = 0;
}
else if(hexrev[i][1] == '5')
{
values[4 * i + 4] = 0;
values[4 * i + 5] = 1;
values[4 * i + 6] = 0;
values[4 * i + 7] = 1;
}
else if(hexrev[i][1] == '6')
{
values[4 * i + 4] = 0;
values[4 * i + 5] = 1;
values[4 * i + 6] = 1;
values[4 * i + 7] = 0;
}
else if(hexrev[i][1] == '7')
{
values[4 * i + 4] = 0;
values[4 * i + 5] = 1;
values[4 * i + 6] = 1;
values[4 * i + 7] = 1;
}
else if(hexrev[i][1] == '8')
{
values[4 * i + 4] = 1;
values[4 * i + 5] = 0;
values[4 * i + 6] = 0;
values[4 * i + 7] = 0;
}
else if(hexrev[i][1] == '9')
{
values[4 * i + 4] = 1;
values[4 * i + 5] = 0;
values[4 * i + 6] = 0;
values[4 * i + 7] = 1;
}
else if(hexrev[i][1] == 'A' || hexrev[i][1] == 'a')
{
values[4 * i + 4] = 1;
values[4 * i + 5] = 0;
values[4 * i + 6] = 1;
values[4 * i + 7] = 0;
}
else if(hexrev[i][1] == 'B' || hexrev[i][1] == 'b')
{
values[4 * i + 4] = 1;
values[4 * i + 5] = 0;
values[4 * i + 6] = 1;
values[4 * i + 7] = 1;
}
else if(hexrev[i][1] == 'C' || hexrev[i][1] == 'c')
{
values[4 * i + 4] = 1;
values[4 * i + 5] = 1;
values[4 * i + 6] = 0;
values[4 * i + 7] = 0;
}
else if(hexrev[i][1] == 'D' || hexrev[i][1] == 'd')
{
values[4 * i + 4] = 1;
values[4 * i + 5] = 1;
values[4 * i + 6] = 0;
values[4 * i + 7] = 1;
}
else if(hexrev[i][1] == 'E' || hexrev[i][1] == 'e')
{
values[4 * i + 4] = 1;
values[4 * i + 5] = 1;
values[4 * i + 6] = 1;
values[4 * i + 7] = 0;
}
else if(hexrev[i][1] == 'F' || hexrev[i][1] == 'f')
{
values[4 * i + 4] = 1;
values[4 * i + 5] = 1;
values[4 * i + 6] = 1;
values[4 * i + 7] = 1;
}
else
int q = 4;
cout << values[0] << endl << values[1] << endl << values[2] << endl << values[118] << endl << values[119] << endl;
system("PAUSE");``````
2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by griproller

You don't need anywhere near this many lines to convert from hex to binary. I would convert from a hex character to an integer from 0 to 15, then just do this:

``````int hexValue;
// code to put a number from 0 to 15 into hexValue;
values[4 * i] = hexValue / 8;
values[4 * i + 1] = (hexValue % 8) / 4;
values[4 * i + 2] = (hexValue % 4) / 2;
values[4 * i + 3] = hexValue % 2;``````

You don't need anywhere near this many lines to convert from hex to binary. I would convert from a hex character to an integer from 0 to 15, then just do this:

``````int hexValue;
// code to put a number from 0 to 15 into hexValue;
values[4 * i] = hexValue / 8;
values[4 * i + 1] = (hexValue % 8) / 4;
values[4 * i + 2] = (hexValue % 4) / 2;
values[4 * i + 3] = hexValue % 2;``````