zero shift

  • Thread starter Mike - EMAIL IGNORED
  • Start date
M

Mike - EMAIL IGNORED

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.
 
K

Kai-Uwe Bux

Mike said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top