help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 64 bit problem with bitoperation


From: Paul Pluzhnikov
Subject: Re: 64 bit problem with bitoperation
Date: Thu, 02 Aug 2007 08:42:37 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

Patrick <sportfreund@gmx.at> writes:

> I wanna do a simple xor of two 64 bit variables as in the following
> code fragment:
>
>    unsigned long long test0 = 0x8888000000001210LL;
>    unsigned long long test1 = 0x88111111111100EFLL;
>    unsigned long long test2;
>
>    test2 = test0 | test1;

That does OR, not XOR. If you really wanted XOR, time to crack that
intro C book open again.

>    printf("0x%016x ",test2);
>
> Unfortuantely only the lower 32 bits of the result are correct as the
> output shows

That's because if you want to print a long (or long long) value,
you must use appropriate printf format. Time to turn on gcc warnings:

$ gcc -Wall junk.c
junk.c: In function 'main':
junk.c:11: warning: format '%016x' expects type 'unsigned int', but argument 2 
has type 'long long unsigned int'

> Anyone an idea why the higher 32 bits are not affected by the
> bitoperation?

They are affected, but due to a bug in your program they are not
printed correctly.

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]