Large numbers in Tcl???
Author Message
Large numbers in Tcl???

I'm trying to get a memory address range in Tickle to read some
information stored there. It is on a flash card that is used as program
memory.

I use the hex address 0FFF01000 and convert it to decimal. The actual
decimal value is 4293922816, however when I do a scan (scan \$hex_addr
"%x" dec_addr) I get a value of 2147483647 which is 7FFFFFFF in hex. If
I then add a value to this (to get the end of the memory location to
read from) I get a negative number. I am obviously exceeding the Tcl
integer max value. How can I overcome this max number problem so I can
set a correct memory location to read from???

Sat, 08 Mar 2003 03:00:00 GMT
Large numbers in Tcl???
Hi Craig,

Quote:
> I use the hex address 0FFF01000 and convert it to decimal. The actual
> decimal value is 4293922816, however when I do a scan (scan \$hex_addr
> "%x" dec_addr) I get a value of 2147483647 which is 7FFFFFFF in hex.

Looks like [scan] gets confused.  Note that Tcl does only use the C
type signed long, there is AFAIK no unsigned math in Tcl.  This is
probably the reason why [scan FFF01000 %x] fails.

Could you just use 0xFFF01000 instead, and not use [scan] at all?  If
you _have_ to convert to decimal you can use [expr 0xFFF01000] or even
[expr 0x0FFF01000], both seem to work fine on Tcl 8.3.2, giving
-1044480.

so long, benny
--
ISION Internet AG
Benjamin Riefenstahl

Ruhrstrasse 61
D-22761 Hamburg
http://www.ision.net

Sat, 08 Mar 2003 03:00:00 GMT
Large numbers in Tcl???
The EXPR function works OK but it still returns a negative number. I need a
double integer so I can create a positive integer in the 4293922816 and
greater range. Does Tcl allow integers in this range. I am working with a
JTAG probe to access the memory area and I need the large number for this.
Quote:

> Hi Craig,

> > I use the hex address 0FFF01000 and convert it to decimal. The actual
> > decimal value is 4293922816, however when I do a scan (scan \$hex_addr
> > "%x" dec_addr) I get a value of 2147483647 which is 7FFFFFFF in hex.

> Looks like [scan] gets confused.  Note that Tcl does only use the C
> type signed long, there is AFAIK no unsigned math in Tcl.  This is
> probably the reason why [scan FFF01000 %x] fails.

> Could you just use 0xFFF01000 instead, and not use [scan] at all?  If
> you _have_ to convert to decimal you can use [expr 0xFFF01000] or even
> [expr 0x0FFF01000], both seem to work fine on Tcl 8.3.2, giving
> -1044480.

> so long, benny
> --
> ISION Internet AG
> Benjamin Riefenstahl

> Ruhrstrasse 61
> D-22761 Hamburg
> http://www.ision.net

Sat, 08 Mar 2003 03:00:00 GMT
Large numbers in Tcl???

Quote:
> I'm trying to get a memory address range in Tickle to read some
> information stored there. It is on a flash card that is used as
program
> memory.

> I use the hex address 0FFF01000 and convert it to decimal. The actual
> decimal value is 4293922816, however when I do a scan (scan \$hex_addr
> "%x" dec_addr) I get a value of 2147483647 which is 7FFFFFFF in hex.
If
> I then add a value to this (to get the end of the memory location to
> read from) I get a negative number. I am obviously exceeding the Tcl
> integer max value. How can I overcome this max number problem so I can
> set a correct memory location to read from???

You might want to try:
http://mini.net/cgi-bin/wikit/683.html

bob

Sent via Deja.com http://www.deja.com/

Sat, 08 Mar 2003 03:00:00 GMT
Large numbers in Tcl???

Quote:

>You might want to try:
>http://mini.net/cgi-bin/wikit/683.html
>bob

the procedures shown there could be made more efficient, if
- more than one digit is handled at a time.
("super-digits" with a range from 0-9999 as list-elements,
the superdigits themselves being written as decimal strings)
- if little-endian order were used within the lists.
(advantage: it's easier to iterate over two different-length
that way, because you don't need to "shift" the lists
disadvantage: converting back to a decimal string
requires string reversing rather than just a [join ...])

I've once posted in a thread on a similar topic.

PS: would be cool, if one could use the "simple object system"
to encapsulate all the  mega-int operations.
iirc, Donal posted about that, some time ago.

Sun, 09 Mar 2003 03:00:00 GMT

 Page 1 of 1 [ 5 post ]

Relevant Pages