source: git/factory/gf_tabutil.cc @ dccceb

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