Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > zero shift

Reply
Thread Tools

zero shift

 
 
Mike - EMAIL IGNORED
Guest
Posts: n/a
 
      03-30-2007
Given:
unsigned x = 123;
unsigned y = 0;
unsigned a = x << y;
unsigned b = x >> y;

I would hope that: a == 123 && b == 123;

but I don't see this in section 5.8 of ISO/IEC 14882.
Is it true? Chapter & verse?

Thanks,
Mike.


 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      03-30-2007
Mike - EMAIL IGNORED wrote:

> Given:
> unsigned x = 123;
> unsigned y = 0;
> unsigned a = x << y;
> unsigned b = x >> y;
>
> I would hope that: a == 123 && b == 123;
>
> but I don't see this in section 5.8 of ISO/IEC 14882.
> Is it true? Chapter & verse?


I think[5.8] covers that case: the right operand is neither negative nor
greater than or equal to the length of the promoted left operand. Thus,
[5.8/1] does not say it's undefined.

For x << y, now [5.8/2] kicks in. We are told that the result is x * 2^y.
Since 2^0 = 1, we find a = x = 123.

For x >> y, [5.8/3] says b = x / ( 2^y) = x /1 = 123.


Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java left shift and right shift operators. Sanny Java 38 04-29-2011 10:02 PM
what "shift" does, if not "$_ = shift;" ? devphylosoff Perl Misc 3 12-04-2007 12:27 AM
Left Shift / Right Shift Operators Santosh Nayak C Programming 16 11-30-2006 05:10 PM
Shift - byte[] buf shift Roberto Gallo Java 3 01-27-2004 04:26 PM
left shift then right shift an unsigned int Wenjie C++ 3 07-11-2003 08:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57