On 2002.02.25, Rob Mayoff <[EMAIL PROTECTED]> wrote:
> +---------- On Feb 25, [EMAIL PROTECTED] said:
> > Can anyone help figure out why expr will not accept any values bigger
> > than that,
>
> Because your Tcl interpreter uses 32-bit signed integers.
>
> proc dotted_ip_from_long {n} {
>     binary scan [binary format I $n] c4 signed_octets
>     set octets {}
>     foreach octet $signed_octets {
>         lappend octets [expr {$octet & 0xff}]
>     }
>     join $octets .
> }

Damn you.  I couldn't remember "binary" -- too lazy to fire
off apropos :-).  That is, of course, the right solution,
similar to the one I've used in Perl which uses pack() and
unpack().

(using Rob's version of dotted_ip_from_long):

% time {dotted_ip_from_long 2130706433} 10000
194 microseconds per iteration

Of course, Rob's version only works under Tcl8, where I
(think) my version will also work on Tcl7 unmodified ...

-- Dossy

--
Dossy Shiobara                       mail: [EMAIL PROTECTED]
Panoptic Computer Network             web: http://www.panoptic.com/
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)

Reply via email to