working with binary numbers with bitwise operators

Dar Scott dsc at swcp.com
Sun May 30 02:16:26 EDT 2004


On Saturday, May 29, 2004, at 11:33 PM, Alejandro Tejada wrote:

> If i convert this 48 bit binary number in decimal
> then i get a negative number:
>
> put baseconvert
> (010011001100001110101010101101100101110111010101,2,10)
>
> results in
> -2864078293

There may be two factors here.

Bugzilla 38 describes a problem in base conversions to base 10.

The baseconvert() function uses a 32 bit environment.

>
> and i've noticed that the function "bitnot" produces
> this result:
>
> put bitnot 35 produces 4294967260
> put bitnot 52 produces 4294967243

The bit-logical operators use a 32-bit environment.

If you need more than 32 bits you might need to build up multiple 
32-bit numbers or (as you did for shifting) use strings of 0 and 1.

If you need to use bit shifting (and rotating) with the bit logical 
operators, you might want to make the number version.

Dar Scott



More information about the use-livecode mailing list