spielwiese
Last change
on this file since d8a7da was
362fc67,
checked in by Martin Lee <martinlee84@…>, 12 years ago
|
chg: remove $Id$
|
-
Property mode set to
100644
|
File size:
973 bytes
|
Line | |
---|
1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | |
---|
3 | #include "config.h" |
---|
4 | |
---|
5 | #include "cf_assert.h" |
---|
6 | |
---|
7 | #include "cf_defs.h" |
---|
8 | #include "gf_tabutil.h" |
---|
9 | |
---|
10 | int gf_tab_numdigits62 ( int q ) |
---|
11 | { |
---|
12 | if ( q < 62 ) |
---|
13 | return 1; |
---|
14 | else if ( q < 62*62 ) |
---|
15 | return 2; |
---|
16 | else |
---|
17 | return 3; |
---|
18 | } |
---|
19 | |
---|
20 | char conv62 ( int i ) |
---|
21 | { |
---|
22 | if ( i < 10 ) |
---|
23 | return '0' + char(i); |
---|
24 | else if ( i < 36 ) |
---|
25 | return 'A' + char(i-10); |
---|
26 | else |
---|
27 | return 'a' + char(i-36); |
---|
28 | } |
---|
29 | |
---|
30 | void convert62 ( int i, int n, char * p ) |
---|
31 | { |
---|
32 | for ( int j = n-1; j >= 0; j-- ) { |
---|
33 | p[j] = conv62( i % 62 ); |
---|
34 | i /= 62; |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | int convback62 ( char c ) |
---|
39 | { |
---|
40 | if ( c >= '0' && c <= '9' ) |
---|
41 | return int(c) - int('0'); |
---|
42 | else if ( c >= 'A' && c <= 'Z' ) |
---|
43 | return int(c) - int('A') + 10; |
---|
44 | else |
---|
45 | return int(c) - int('a') + 36; |
---|
46 | } |
---|
47 | |
---|
48 | int convertback62 ( char * p, int n ) |
---|
49 | { |
---|
50 | int r = 0; |
---|
51 | for ( int j = 0; j < n; j++ ) |
---|
52 | r = r * 62 + convback62( p[j] ); |
---|
53 | return r; |
---|
54 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.