baseConvert() & 32-bit ops

Dar Scott dsc at swcp.com
Mon Jun 23 00:00:00 EDT 2003


On Sunday, June 22, 2003, at 10:29 PM, Mark Brownell wrote:

> Dar wrote:
>
>>>>   put ( xL bitAnd -16777216 ) / 16777216 into zap
>>>
>>> 4278190080 not -16777216.
>>>
>>> (Soap box diatribe about our C heritage deleted.)
>
> There must be a relationship for these two numbers being treated the 
> same. How about some kind of truncation procedure that worked in 
> Director but not Revolution.  I traded 4278190080 for all instances  
> of -16777216 in my Director version. It worked perfect for all 
> instances of a, b, c, and d.

Yes.

You want hex FF000000.  If a signed 32-bit variable is used (oh, shame, 
shame) then thats -16777216.  If an unsigned 32-bit variable is used, 
then thats 4278190080.  Note that 2^32 - 16777216 = 4278190080.  In 
Revolution, we pretend an unsigned 32-bit variable.

Note that the numbers you are using in hex are FF000000, 01000000, 
00FF0000, 00010000, 0000FF00, 00000100, and 000000FF.  This code would 
also be easier to understand if it used only 255 and 256 and 
repetitively consumed from the least significant byte.

 From the very beginning of C, programmers have gotten into the habit of 
using int were unsigned int is more appropriate and it has hurt 
programming and programming languages & environments ever since.

Dar Scott




More information about the use-livecode mailing list