Skip to content

Commit dcc6cfb

Browse files
authored
Upgraded to base62
Earlier - [0-9A-Z] ->Base 36 Now - [0-9A-Za-z] -> Base 62
1 parent 19af629 commit dcc6cfb

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

BaseConversionAlgorithm V3.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
using namespace std;
88

9-
char DIGITS[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";;
9+
const char DIGITS[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
1010

1111
const long int MAX = 1000000;
1212
char inputString[MAX * 2];
@@ -22,8 +22,10 @@ unsigned int fractionOut[MAX] = {0};
2222
void display(long int n, long int f)
2323
{
2424
long int k;
25-
for (k = n; k >= 0; k--)
25+
for (k = n; k >= 0; k--){
2626
cout << DIGITS[ integerWork[k] ];
27+
//cout << integerWork[k] <<"|";
28+
}
2729

2830
// Only print fractional part if f >= 0 (meaning some fractional digits were produced)
2931
if (f >= 0 && !(f == 0 && fractionOut[0] == 0))
@@ -126,11 +128,21 @@ int main()
126128
// convert ASCII to numeric (in-place)
127129
for (i = 0; i < integerInputLen; i++)
128130
{
129-
if (inputString[i] > 57) // A-F etc
130-
inputString[i] -= 7;
131-
inputString[i] -= 48; // '0'
131+
if (inputString[i] >= '0' && inputString[i] <= '9')
132+
{
133+
inputString[i] = inputString[i] - '0';
134+
}
135+
else if (inputString[i] >= 'A' && inputString[i] <= 'Z')
136+
{
137+
inputString[i] = inputString[i] - 'A' + 10; // 10–35
138+
}
139+
else if (inputString[i] >= 'a' && inputString[i] <= 'z')
140+
{
141+
inputString[i] = inputString[i] - 'a' + 36; // 36–61
142+
}
132143
}
133144

145+
134146
// copy fraction part reverse into fractionWork[]
135147
k = 0;
136148
for (i = integerInputLen - 1; i > p; i--)

0 commit comments

Comments
 (0)