forked from Singular/Singular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgf_tabutil.cc
56 lines (46 loc) · 975 Bytes
/
gf_tabutil.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* emacs edit mode for this file is -*- C++ -*- */
#include "config.h"
#include "cf_assert.h"
#include "cf_defs.h"
#include "gf_tabutil.h"
int gf_tab_numdigits62 ( int q )
{
if ( q < 62 )
return 1;
else if ( q < 62*62 )
return 2;
else
return 3;
}
char conv62 ( int i )
{
if ( i < 10 )
return '0' + char(i);
else if ( i < 36 )
return 'A' + char(i-10);
else
return 'a' + char(i-36);
}
void convert62 ( int i, int n, char * p )
{
for ( int j = n-1; j >= 0; j-- ) {
p[j] = conv62( i % 62 );
i /= 62;
}
}
int convback62 ( char c )
{
if ( c >= '0' && c <= '9' )
return int(c) - int('0');
else if ( c >= 'A' && c <= 'Z' )
return int(c) - int('A') + 10;
else
return int(c) - int('a') + 36;
}
int convertback62 ( char * p, int n )
{
int r = 0;
for ( int j = 0; j < n; j++ )
r = r * 62 + convback62( p[j] );
return r;
}