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

  • Home
  • SEARCH
  • 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 6789627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:37:37+00:00 2026-05-26T17:37:37+00:00

Assume I have the variable x initialized to 425 . In binary, that is

  • 0

Assume I have the variable x initialized to 425. In binary, that is 110101001.

Bitshifting it to the right by 2 as follows: int a = x >> 2;, the answer is: 106. In binary that is 1101010. This makes sense as the two right-most bits are dropped and two zero’s are added to the left side.

Bitshifting it to the left by 2 as follows: int a = x << 2;, the answer is: 1700. In binary this is 11010100100. I don’t understand how this works. Why are the two left most bits preserved? How can I drop them?

Thank you,

  • 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-05-26T17:37:37+00:00Added an answer on May 26, 2026 at 5:37 pm

    This is because int is probably 32-bits on your system. (Assuming x is type int.)

    So your 425, is actually:

    0000 0000 0000 0000 0000 0001 1010 1001
    

    When left-shifted by 2, you get:

    0000 0000 0000 0000 0000 0110 1010 0100
    

    Nothing gets shifted off until you go all the way past 32. (Strictly speaking, overflow of signed-integer is undefined behavior in C/C++.)

    To drop the bits that are shifted off, you need to bitwise AND against a mask that’s the original length of your number:

    int a = (425 << 2) & 0x1ff;  //  0x1ff is for 9 bits as the original length of the number.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that I have a global variable user in application....like this: # GET /users.xml
I have two questions relative to CMake Assume that we have a variable ${MY_CURRENT_DIR}
Assume you have a relation that needs to somehow reference any (variable) number of
Assume that the int variables i and j have been declared, and that n
For some reason I have always assumed that most of the time a variable
Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
In Java, assume I have the following class Container that contains a list of
Assume I have an instance foo of some class Class with some variable foo.x.
Assume I have a variable, which is a List(Of T) , with 100 elements
I have a class and a const variable. struct A { int b; };

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.