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 9151953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:55:35+00:00 2026-06-17T11:55:35+00:00

Could any one please help me in understanding the following behaviour. 1 #include <iostream>

  • 0

Could any one please help me in understanding the following behaviour.

    1    #include <iostream>
    2
    3    using namespace std;
    4
    5    main()
    6    {
    7        uint32_t i = 32;
    8
    9        // cout << "(1<<32): " << (1<<32) << endl; // - This leads to a compilation error.
    10       cout << "(1<<32): " << (1<<i) << endl; // - This compiles and prints 1 - Why?
    11
    12        return 0;
    13    }

If I un-comment the line number 9 above – I see the following compilation error (which makes sense to me)

BitWiseLeftShift.c++: In function 'int main()':
BitWiseLeftShift.c++:9: warning: left shift count >= width of type

But the line number 10 is where my question is. It compiles successfully and prints

(1<<32): 1

something like a circular bit shift. Why would it print 1?
And I have seen that for i == 33, (1<<i) prints 2.

I did search the forum and could not find a relevant question. If this is a duplicate question – please help me with a link.

  • 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-17T11:55:36+00:00Added an answer on June 17, 2026 at 11:55 am

    As pointed out in other answers, if the shift amount is larger or equal to the size of the shifted data in bits (or is negative), the result is undefined.

    However, to explain the behavior you are seeing –

    Some computer architectures (including x86) treat the shift amount as modulo the size of the data being shifted, so shifting by 32 is equivalent to not shifting at all. To put it another way, they simply mask out the higher bits and use the lower bits.

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

Sidebar

Related Questions

could any one please help us to retrieve data from incoming message in blackberry
Why the mail function not sending mail to me ,Could any one please help
Could any one help me understand the below code. Please help me how it
Could anyone please help me using C# Api in Z3. I have no idea
Could any one please tell me the meaning of ++ with array in the
I'm developing a windows form application. Could any one please advise what are the
I have written the below SP and getting below error. Could any one please
Which pattern is identified by PATINDEX in the below statement? Could any one help
can any one help me on how can I create a query output using
Could anyone please help me convert this code to vb.net, I have tried it

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.