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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:42:14+00:00 2026-06-05T14:42:14+00:00

I have looked over the guide given in this answer , but I still

  • 0

I have looked over the guide given in this answer, but I still don’t understand bit-shifting. In particular I am confused about the data types come into play.

The following:

unsigned int a = pow(2,31);
cout << (a << 1);

indeed produces 0 as I expect because the int is 32 bits, so moving the 1 to the left, pushes it into nothing.

But the following

unsigned int a = 1;
unsigned char b = (unsigned char)a;
cout << (unsigned int)(b<<8);

produces 256. Why is that? My guess would have been that a char is 8 bit and so moving 1 left 8 places should give zero.

Is there a function/shift that does this? (i.e. evaluates 1<<8 to 0).

  • 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-05T14:42:16+00:00Added an answer on June 5, 2026 at 2:42 pm

    Narrow integral values are promoted to int or unsigned int before being used. It’s called integral promotion.

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

Sidebar

Related Questions

I have looked all over but can't find an answer to this... Quite simply
Have looked quite hard for this answer but having no luck. I have 3
I don't really know why I have this issue, I have looked over my
I have looked over other questions on this website, but am yet to find
I have looked all over and cannot figure out why this code isn't working.
I am re-hashing this question because I have looked at over 50 threads in
I have looked all over and can't figure this out: how do you target
I have looked all over and found no solution, any help on this would
I have looked all over for an answer and hope someone here can help.
I keep getting the same error: Missing Operator. I have looked over this code

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.