1 /******************************************************************************
2 *
3 * Copyright (C) 2006, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * ID: num32 20.11.06 0.0.A.
11 *
12 * Author: Alexey Krivonogov ( gentee )
13 *
14 * Summary: 32-based numbers.
15 *
16 ******************************************************************************/
17
18 private
19
20 global
21 {
22 collection letters = %{ '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
23 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L',
24 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
25 'Y', 'Z' }
26 arr num2key key2num
27 }
28
29 public
30
31 func str32x_init< entry >
32 {
33 uint i val
34
35 key2num.expand( 256 )
36 fornum i, 32
37 {
38 val = letters[ i ]
39 num2key += val
40 key2num[ val ] = i
41 }
42 }
43
44 method uint str.str32x2uint
45 {
46 uint result i
47
48 fornum i, *this
49 {
50 result <<= 5 // Сдвиг на 5 бит
51 result += key2num[ this[ i ]]
52 }
53 return result
54 }
55
56 method str str.uint2str32x( uint val )
57 {
58 uint i
59
60 this.clear()
61 while val
62 {
63 this.insert( 0, "".appendch( num2key[ val & 31 ] ))
64 val >>= 5 // Сдвиг на 5 бит
65 }
66 if !*this : this.appendch( num2key[0] )
67
68 return this
69 }
70
Редактировать