[Tutor] built in functions int(),long()

Gerrit Holl gerrit@nl.linux.org
Wed Jun 18 08:17:01 2003


cino hilliard wrote:
> These do not work properly or as defined.
> examples
> >>>long('123',2)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> ValueError: invalid literal for long(): 123

This is correct. Base 2 means only 0 and 1 can occur.

> >>>
> >>>long('123')
> 123L                            OK
> >>>
> >>>long("123",10)
> 123L                           OK
> >>>long('123',4)
> 27L                                      base 10  123 base 4 = 1323

This is all correct.

b10 b4
0   0
1   1
2   2
3   3
4   10
5   11
6   12
7   13
8   20
9   21
10  22
11  23
12  30
13  31
14  32
15  33
16  100
17  101
18  102
19  103
20  110
21  111
22  112
23  113
24  120
25  121
26  122
27  123

What is the problem?

yours,
Gerrit.

-- 
52. If the cultivator do not plant corn or sesame in the field, the
debtor's contract is not weakened.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/