> -----Original Message-----
> From: Leopold Toetsch [mailto:[EMAIL PROTECTED]
> Sent: Friday, May 07, 2004 3:59 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [perl #29402] [BUG] 64-bit bitops
> 
> > One particularly odd case:
> 
> > _main:
> >         set I1, 0xffffffff
> >         shl I1, I1, 32
> >         set I2, 0xffffffff
> >         band I2, I2, I1
> 
> What does
>           print I2
> show here?
> 

Revised:

_main:
    set I1, 0xffffffff
    shl I1, I1, 32
    set I2, 0xffffffff
    print I2 # prints -1
    print "\n"
    band I2, I2, I1
    print I2 # prints -4294967296
    print "\n"
    new P1, 32
    set P1, 2
    set P1[0], I1
    set P1[1], I2
    sprintf S1, "%lx %lx\n", P1 # still prints ffffffff00000000 ffffffff00000000
    print S1
end

Why would the decimal value of 0xffffffff be -1 with 64-bit ints?  Is this a printf 
problem or is the sign boundary actually at 0x000000007fffffff?

For reference, here's the C equivalent:

int main( )
{
    long I1 = 0xffffffff;
    long I2 = 0xffffffff;
    I1 <<= 32;
    printf( "%ld\n", I2 ); /* prints 4294967295 */
    I2 = I1 & I2;
    printf( "%ld\n", I2 ); /* prints 0 */
    printf( "%lx %lx\n", I1, I2 ); /* prints ffffffff00000000 0 */
}

Reply via email to