little-dude
little-dude

Reputation: 1674

tcl : manipulating numbers bigger than 0xFFFFFFFF with `format`

I need to do some operation on MAC addresses, coded on 48 bits, but format truncates the results :

format 0x%x 0x100000000 ;# --> 0x0

Is it possible to do something for this, or must I adapt my code to use smaller numbers ?

Upvotes: 0

Views: 395

Answers (1)

Marco Pallante
Marco Pallante

Reputation: 4043

In Tcl 8.4 just give the size modifier l to the field specificator of format. This way, you tell format to interpret the value as (at least) 64-bit number (same size of wide(), which is machine dependent):

format 0x%lx 0x100000000

(Note that it is a lower case el letter, not the one digit.)

In Tcl 8.5 and later, integer math is done with arbitrary precision and the ll size modifier tells format to not truncate the value:

format 0x%llx 0x100000000

(Again, they are two lower case el letters, not two one digits.)

Upvotes: 3

Related Questions