Newbie Req: Integer Handling

Greg Ewing greg at
Tue Mar 21 05:35:11 CET 2000

Remco Gerlich wrote:
> Aesop wrote in comp.lang.python:
> > is it possible to set up direct pointers and indirection operators as in C
> > that could be used to examine integer variables on the fly?

As Remco Gerlich said at greater length, no. But doing that
wouldn't help you with your problem even in C, because there's
no way to point to an individual *decimal* digit in a binary
integer. You'd have to store the number in decimal, one digit
per byte, and then you're faced with either converting to
binary to do arithmetic, or writing procedures to do arithmetic
directly in decimal.

So you'll have to choose one representation -- decimal or
binary -- as your base representation, and convert when needed.
Which one is easier/faster/more convenient will depend on what
you do more often, arithmetic or digit manipulation.

Since the digits are to be part of a crossword puzzle, the
thought which comes to my mind is to store the grid as a
2D array (either a list of lists, or a 2D NumPy array) of
digits, with methods for inserting and extracting numbers
(as integers) from a specified subrange of a row or column.

If you store the digits as 1-character strings, you should
be able to convert fairly quickly to integers and back once
you've extracted the digits, e.g. to convert a list of digits
to an integer,

  int(string.join(digits, ''))

and the other way


Hope that gives you some ideas,

Greg Ewing, Computer Science Dept,
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at	   +--------------------------------------+

More information about the Python-list mailing list