Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8668537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:14:17+00:00 2026-06-12T18:14:17+00:00

I am working on bit shifts, and I’ve run into this problem. I have

  • 0

I am working on bit shifts, and I’ve run into this problem.
I have two int:

int x = 1;
int y = 2;

What is the difference between:

 x = x << (31 + 1);

and

 y = y << 31;

I thought the result would be the same (namely that x and y would both equal 1) , but they aren’t…..I don’t understand why. 2 is just 1 with a “1” bit moved one space to the left.

Thanks!

I mean when we can’t shift-left anymore, don’t we wrap around to the beginning?

EDIT:
Let me clarify what I THINK is going on:

We start with x = 1, so that’s:

 00000000 00000000 00000000 00000001

We then left shift that by 31 +1 (or 32). That gives us:

 00000000 00000000 00000000 00000001

which is also 1.

Then we do y = 2, so that’s

 00000000 00000000 00000000 00000010

We left shift that by 31. That also gives us:

 00000000 00000000 00000000 00000001

Therefore, we get x = y = 1. I know this is wrong, but can anyone explain why???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:14:18+00:00Added an answer on June 12, 2026 at 6:14 pm

    You are confusing shifting with rotating:

    • Shifting means shifting all bits and filling the empty spot with a 0
      or a 1 (depending on value and/or signedness).

    • Rotating is shifting all bits and filling the empty spot with the bit
      that “fell out” in the end.

    AFAIK C does not support rotating, but only shifting (probably because of platform dependencies?). x86 assembler implements both shift and rotate operations.

    A explanation better than I can give here, can be found here: http://en.wikibooks.org/wiki/X86_Assembly/Shift_and_Rotate

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem getting password_Reset_confirm bit working. url: (r'^password_reset/$', 'django.contrib.auth.views.password_reset'), (r'^password_reset_done/$', 'django.contrib.auth.views.password_reset_done'), (r'^password_reset_confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
Hi I was working on a bit of fun, making an interface to run
I'm working on a bit of a project in Python. I have a list
I have this code which shifts the alphabet by a certain amount. The size
I was working a bit ahead and planning for transition from EF 4.2 CTP
I'm working on a bit of c# code that first has the user click
I've started working a little bit with lift+scala+mongorecord but I found a small annoyance
I've been slowly and a bit painfully working my way up the datastore/JDO learning
I was wondering if someone can help me out - working on a bit
Horrible title I know, horrible question too. I'm working with a bit of software

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.