shifting bits, shift 32 bits on 32 bit int

From: GGG (gschoep_at_DigitalGlobe.com)
Date: 05/26/04


Date: 26 May 2004 11:29:07 -0700

Noticed something odd in the way bit shifting was working today.

As far as I have ever heard, shifting will shift in zeros(signed ints
aside)

However I foudn something odd when I am shifting exactly the number of
bits in a value... i.e.

uint32_t x = 5;
uint32_t y = x << 32;
uint32_t z = x << 32;
 
In the above example y and z are both still 5. Why is this?

Now I understand doing a shift like this seems silly, but in this code
sometimes the resulting shift validly turns out to be exactly the
number of bits in that data type, and expects the result to be 0.

I can change the code to handle this special case... I was just
wondering why this was happening..



Relevant Pages

  • Re: Re: Difficult shift from 1st to 2nd
    ... >> There is the possibility your clutch isn't disengaging enough, ... check your shifter pedal to make sure that it is clamped ... So the shifter drum has to be rotated further to shift ... >> second than it has to move shifting from second to third, ...
    (rec.motorcycles.tech)
  • Re: Shifting problems
    ... More specifically, when shifting the ... SRAM MRX 8-Speed Twist Shift ... Shimano 8 Speed Chain - IG ... Once the derailleur limits are set, ensure the gear wire moves freely and that there are no kinks, frays or other damage to the wire or casing. ...
    (rec.bicycles.tech)
  • Re: Dynamically resizing a buffer
    ... Code using a lot of shifts for shifting bits, NOT for division, could be ... So whether a scaling process can be seen as a shift depends on the ... representation. ... | an unsigned type or if E1 has a signed type and a nonnegative value, ...
    (comp.lang.c)
  • Re: Dynamically resizing a buffer
    ... Because you consider shift an appropriate method of halving a number. ... you would have to consider unsigned and signed as different because right shifting negative numbers is not guaranteed to act as division. ... It does, however, show that you are thinking of manipulating the representation rather than the fundamental concept. ... Exponential is also a natural growth curve, if you don't believe me check how populations grow in nature, for at least some it is exponential until a crash. ...
    (comp.lang.c)
  • Re: Dynamically resizing a buffer
    ... Because you consider shift an appropriate method of halving a number. ... define the result of right shifting a negative number). ... however, I reason, almost none of my crap is ever likely to be run on ... Linear is another natural growth curve. ...
    (comp.lang.c)