Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem using hexadecimal [format] on integers

24 views
Skip to first unread message

Erik Leunissen

unread,
Apr 19, 2008, 10:46:05 AM4/19/08
to
Consider:

% format %x [expr 0x5ade3412ab]
de3412ab
% format %10x [expr 0x5ade3412ab]
de3412ab

Why doesn't [format] return the two leading digits "5a"?

I'm probably overlooking something, but can't see what.


Any help greatly appreciated,

Erik
--
leunissen@ nl | Merge the left part of these two lines into one,
e. hccnet. | respecting a character's position in a line.

belzebutt

unread,
Apr 19, 2008, 11:09:55 AM4/19/08
to
Erik Leunissen a écrit :

> Consider:
>
> % format %x [expr 0x5ade3412ab]
> de3412ab
> % format %10x [expr 0x5ade3412ab]
> de3412ab
>
> Why doesn't [format] return the two leading digits "5a"?
>
> I'm probably overlooking something, but can't see what.
>
>
> Any help greatly appreciated,
>
> Erik

format %i [expr 0x5ade3412ab]

-567012693

seems that you are out of range of hexa values regarding internal
registering, try with smaller figures

Erik Leunissen

unread,
Apr 19, 2008, 11:29:29 AM4/19/08
to
belzebutt wrote:

> format %i [expr 0x5ade3412ab]
>
> -567012693
>
> seems that you are out of range of hexa values regarding internal
> registering, try with smaller figures

Right. Thanks for pointing this out.

Uwe Klein

unread,
Apr 19, 2008, 12:08:04 PM4/19/08
to
Erik Leunissen wrote:
> Consider:
>
> % format %x [expr 0x5ade3412ab]
> de3412ab
> % format %10x [expr 0x5ade3412ab]
> de3412ab
>
> Why doesn't [format] return the two leading digits "5a"?
>
> I'm probably overlooking something, but can't see what.
>
>
> Any help greatly appreciated,
>
> Erik

% format %x [expr 0x5ade3412ab]

integer value too large to represent
% format %x [expr wide(0x5ade3412ab) ]
integer value too large to represent
% format %lx [expr wide(0x5ade3412ab) ]
5ade3412ab
% format %x 0x5ade3412ab
integer value too large to represent
% format %lx 0x5ade3412ab
5ade3412ab
%
uwe

Helmut Giese

unread,
Apr 19, 2008, 12:17:43 PM4/19/08
to
On Sat, 19 Apr 2008 16:46:05 +0200, Erik Leunissen
<lo...@the.footer.invalid> wrote:

>Consider:
>
>% format %x [expr 0x5ade3412ab]
>de3412ab
>% format %10x [expr 0x5ade3412ab]
> de3412ab

Hi Eric,
seems like [format] needs a special format for wide integers. Try
format %lx [expr 0x5ade3412ab]
(this is a lower case L) - works for me on this old Tcl 8.4.13 machine
(Windows).
HTH
Helmut Giese

Erik Leunissen

unread,
Apr 19, 2008, 1:43:00 PM4/19/08
to
Uwe Klein wrote:
>
> % format %x [expr 0x5ade3412ab]
> integer value too large to represent

Do you have any idea why you get this helpful error message, and I just
get a plain wrong result?

Do we have different platforms/configurations?

Here's mine:


% format %x [expr 0x5ade3412ab]
de3412ab

% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine) = i686
tcl_platform(os) = Linux
tcl_platform(osVersion) = 2.6.18.8-0.9-default
tcl_platform(platform) = unix
tcl_platform(user) = erik
tcl_platform(wordSize) = 4

<snip>

> % format %lx 0x5ade3412ab
> 5ade3412ab

Thanks for pointing out this useful %lx conversion specifier.

Erik.

> %
> uwe

Erik Leunissen

unread,
Apr 19, 2008, 1:45:49 PM4/19/08
to
Erik Leunissen wrote:
>
> Do we have different platforms/configurations?
>
> Here's mine:
> % format %x [expr 0x5ade3412ab]
> de3412ab
> % parray tcl_platform
> tcl_platform(byteOrder) = littleEndian
> tcl_platform(machine) = i686
> tcl_platform(os) = Linux
> tcl_platform(osVersion) = 2.6.18.8-0.9-default
> tcl_platform(platform) = unix
> tcl_platform(user) = erik
> tcl_platform(wordSize) = 4
>

and

% info patch
8.4.18


Erik

Erik Leunissen

unread,
Apr 19, 2008, 1:48:47 PM4/19/08
to
Helmut Giese wrote:
>
> Hi Eric,
> seems like [format] needs a special format for wide integers. Try
> format %lx [expr 0x5ade3412ab]
> (this is a lower case L) - works for me on this old Tcl 8.4.13 machine
> (Windows).

Works for me too (Linux). Thanks,

Erik.

> HTH
> Helmut Giese

Uwe Klein

unread,
Apr 19, 2008, 2:00:58 PM4/19/08
to
tcl_platform(osVersion) = 2.6.5-7.111.19-default
tcl_platform(platform) = unix
tcl_platform(user) = uwe
tcl_platform(wordSize) = 4
% set tcl_version
8.4
% set tcl_patchLevel
8.4.6

uwe

Erik Leunissen

unread,
Apr 19, 2008, 2:34:45 PM4/19/08
to
Uwe Klein wrote:
>>
> % parray tcl_platform
> tcl_platform(byteOrder) = littleEndian
> tcl_platform(machine) = i686
> tcl_platform(os) = Linux
> tcl_platform(osVersion) = 2.6.5-7.111.19-default
> tcl_platform(platform) = unix
> tcl_platform(user) = uwe
> tcl_platform(wordSize) = 4
> % set tcl_version
> 8.4
> % set tcl_patchLevel
> 8.4.6
>
> uwe
>

Well, that would suggest that something relevant changed in between
8.4.6 and 8.4.18.

Hmm ... well, be that so. I won't pursue this further.

Erik

Donald Arseneau

unread,
Apr 21, 2008, 7:23:53 PM4/21/08
to
On Apr 19, 9:17 am, Helmut Giese <hgi...@ratiosoft.com> wrote:

> seems like [format] needs a special format for wide integers. Try
> format %lx [expr 0x5ade3412ab]

[format] has become a complete mess in Tcl today!
With multiple versions of integer representation
(normal, wide, unlimited; varying by platform)
plus automatic conversion between them, the fixed
size format specifiers are a broken relic from the
past. They require knowledge of a value's special
representation, when that is supposed to be hidden.
Unfortunately, in the beginning, [format] was copied
too blindly from C, but it didn't seem so bad in
those days -- the fixed-size implication of %x and %d
could be viewed as an irrelevant curiosity that had
no effect in Tcl. Now that Tcl has various sized of
integers, entirely different from the system in C,
the carry-over of format specifiers is terrible.
It is a painful hangover.

It seems that recently the meaning of the size
specifiers has changed from a requirement to a
conversion request. This may seem better than
getting type-errors in a typeless language, but
has the bad effect of entrenching and legitimizing
the use of these size-specific tags for type-
conversion. Whereas I would like to have the
simplest forms (%x, %d) work, without conversion,
on all sizes of internal integer.

The question is, would it be feasible to change the
meaning of the format specifiers to drop the size
requirement? Another prefix would have to be introduced
to retain the current behavior for conversion to
regular int.

Donald Arseneau as...@triumf.ca

0 new messages