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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:50:13+00:00 2026-06-14T04:50:13+00:00

Possible Duplicate: What is the << operator in C++? In a piece of code

  • 0

Possible Duplicate:
What is the “<<” operator in C++?

In a piece of code I am looking at, the following takes place:

... (header[4] << 8) + header[5] ...

I’m fairly new to programming and have never seen the << operator before. Googling didn’t provide any results. Any quick pointers would be appreciated!

  • 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-14T04:50:14+00:00Added an answer on June 14, 2026 at 4:50 am

    << operator shifts the bits to left by N bits where N comes after the operator. In your example the bits at the address of header[4] are shifted to left by 8 bits.

    What this is good for is that it effectively results in multiplication by 256, because 2^8 = 256. If it were a shift to right the value at header[4] would be divided by 2^8 = 256.

    Some real bit-level examples:

    • Value of 2 (0010 in binary) shifted to right by 2 bits becomes 1000 which results in value of 8.
    • Value of 7 (0111 in binary) shifted to left by 2 bits becomes 0001) which results in value of 1. (7/4 is 1.75 which gets rounded down because there’s no way to represent fractionals in integer binary values)
    • Value of 31 (11110 in binary) shifted to left by 3 bits becomes 00011 which results in value of 3. (really it becomes 3.785 but it gets rounded down)

    So in the end, very often a bit shift means either multiplication(shift to left) or division(shift to right) because that’s what it results in. That is, you can actually replace multiplications and divisions by power-of-two values with bit shifts, or replace bitshifts with multiplications. Compilers often prefer replacing multiplications and divisions with number of bit shifts because for the computer shifting the bits is much faster than actually doing real multiplication or division of the values.

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

Sidebar

Related Questions

Possible Duplicate: Conditional operator assignment with Nullable<value> types? in the following code snippet company.ParentID
Possible Duplicate: Ternary conditional operator in Python If I have some code like: x
Possible Duplicate: Operator overloading I have to code a clock program in which I
Possible Duplicate: Overload ++ operator Say i have a class in which i overloads
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: Why is this code invalid in C#? Conditional operator cannot cast implicitly?
Possible Duplicate: Conditional operator cannot cast implicitly? I have run into a peculiar situation
Possible Duplicate: Ternary conditional operator in Python I have this problem and have no
Possible Duplicate: Python Ternary Operator Does Python have an equivalent of the ternary operator?:
Possible Duplicate: Operator overloading in C If I have a struct: typedef struct myStruct

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.