Re: Peculiar behavior with bit-shifting

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

 



On Sun, Feb 19, 2017 at 04:44:43PM +0100, Chris Pezley wrote:
> int main( void )
> {
>     int32_t high_part;
>     int32_t low_part;
>     int64_t together;
> 
>     const int64_t id = 0xAAAAAAAAAAAA;
> 
>     high_part = id >> 32;
>     low_part = id & 0xFFFFFFFF;
>     together = (int64_t)high_part << 32 | low_part;

The way you write it, low_part is implicitly cast to int64_t.  It is
signed and negative, so it gets 1 bits in the top half.


Segher



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux