Re: Signed and Unsigned integers in Tcl



Sektor van Skijlen <ethouris@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Hmm...
% set value -32768; format %08x [expr {$value >> 4}]
fffff800

% set value 0xffff8000; format %08x [expr {$value >> 4}]
0ffff800

That's indeed strange, especially as it also happens in Tcl8.4 (.9 here)
It appears to be a "feature" more than a bug, though:
% expr 0xfffff800
4294965248
% set value 4294965248; format %08x [expr {$value >> 4}]
0fffff80

For Tcl8.5 this would be the expected behaviour, anyway, since
integers do no longer wrap around there at all.

So, for example, to "retype" the integer value from signed to unsigned should
be accomplished with:
set value [format %x $value]

You'd also have to prepend the 0x, of course, but yes.

.



Relevant Pages

  • Re: fortran reading a line
    ... note also that reading 1e2 in %d format is not an error in C. ... It seems to me that just having a feature doesn't need to ... that would be a good reason to add it? ...
    (comp.lang.fortran)
  • Re: Numeric literals in other than base 10 - was Annoying octal notation
    ... If you want your data file to have values entered in hex, or oct, or even ... able to choose to prepare the data in a certain format - the format ... When designing a language feature don't be too ready to ... impossible or unreasonable to support a feature then by all means ...
    (comp.lang.python)
  • Re: Code to sort out different dates
    ... I'm searching for a date in a word document. ... but sometimes they use very strange combination. ... "strange format" beforehand, your code will not be able to decipher it ... MessageBox to yourself and ask how you want the program to interpret a date ...
    (microsoft.public.vb.general.discussion)
  • Re: Question about blitting from RGB surface to YUV surface
    ... so if a spec doesnt ask for a feature, the hw guy wont think to add it, ... That and YUV is typically seen as a video format and not a 3D format. ... conversion needed, I should do the work programmly. ... PC with ATI graphic card, I notice that a RGB-format overlay surface was ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: VS 2005 : "Error when trying to run project"??
    ... The host process is enabled by default and it is a feature of visual studio ... Try to disable vs hosting process on project properties, Debug Tab... ... Another strange answer googling is Enable Terminal server services ?! ...
    (microsoft.public.dotnet.general)