digitAt:

Dan Ingalls Dan at SqueakLand.org
Tue Feb 12 16:15:59 UTC 2002


<rallende at harlan.di.unc.edu.ar>  wrote in...

>Hello, where can i read about digitAt: method found on some subclasses of
>numbers, 'cause i readed the description at the implementation and i can't
>understand very well it's meaning.

Well, you found the right place.  The comment says...

"Answer the value of an indexable field in the receiver.  LargePositiveInteger uses bytes of base two number, and each is a 'digit' base 256.  Fail if the argument (the index) is not an Integer or is out of bounds."

So the view is that large numbers are built up of "digits" with 256 values (stored as 8-bit bytes in LargeIntegers).

The results may be a bit confusing however, as they only have meaning in the context of Squeak's LargeIntegers which carry the sign (in their class) separate from the bits.  Therefore, while (N digitAt: 3) will give you what you probably expect (bits 16 through 23 of the binary for N) if N is positive, (N digitAt: d) = (0-N digitAt: d) for all N and d, which you might not expect.

This should probably be clarified in the comment.

	- Dan



More information about the Squeak-dev mailing list