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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:37:48+00:00 2026-06-14T21:37:48+00:00

I am trying to understand the behavior of bitwise operators on signed and unsigned

  • 0

I am trying to understand the behavior of bitwise operators on signed and unsigned types. As per the ISO/IEC document, following are my understandings.

Left shift Operator

  • The result of E1 << E2, is E1 left-shifted E2 bit positions

  • The vacated bits on the account of left shift will be filled by zeros.

  • E1 as signed non-negative: E1 << E2 will result to E1 multiplied by 2 power of E2, if the value is representable by the result type.

  • Q1: What about signed negatives?

  • Q2: I am not able to understand on what’s meant by “reduced modulo” in the following context. “If E1 has an unsigned type, the value of the result is E1 × 2E2 , reduced modulo
    one more than the maximum value representable in the result type”
    .

Right Shift Operator

  • The result of E1 >> E2 is E1 right-shifted E2 bit positions.

  • E1 as signed non-negative/unsigned:The value of the result is the integral part of the quotient of E1 / 2E2

  • Q3: For signed negative integers I see, some books defining that the vacant positions will be filled with 1.Please elaborate more on the use of right shift operator on signed negative int.

  • 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-14T21:37:50+00:00Added an answer on June 14, 2026 at 9:37 pm

    Q1: The behaviour of the left shift operator on negative values of signed integer types is undefined, as is the behaviour for positive values of signed integer types when the result E1 * 2^E2 is not representable in the type.

    That is explicitly mentioned in section 6.5.7, paragraph 4 and 5 of the standard (n1570 draft):

    4 The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros. If E1 has an unsigned type, the value of the result is E1 × 2^E2 , reduced modulo one more than the maximum value representable in the result type. If E1 has a signed type and nonnegative value, and E1 × 2^E2 is representable in the result type, then that is the resulting value; otherwise, the behavior is undefined.

    Q2: The reduction modulo one more than the maximum value representable in the unsigned integer type means that the bits that are shifted out on the left are simply discarded.

    Mathematically, if the maximal value of the unsigned type is 2^n - 1 (and it is always of that form), the result of shifting E1 left by E2 bits is the value V in the range from 0 to 2^n - 1 such that the difference

    (E1 * 2^E2 - V)
    

    is divisible by 2^n, that is, it’s the remainder you get when dividing E1 * 2^E2 by 2^n.

    Q3: The behaviour upon shifting right negative values of signed integer types is implementation-defined. The most common behaviour (at least on two’s complement machines) is an arithmetic shift, that is, the result is the quotient rounded down (towards negative infinity).

    5 The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of E1 / 2^E2 . If E1 has a signed type and a negative value, the resulting value is implementation-defined.

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

Sidebar

Related Questions

I'm trying to understand the behavior of Scala for-loop implicit box/unboxing of numerical types.
I am trying to understand the behavior of vector::pop_back() . So I have following
I am trying to understand the behavior of the following code in a WinForms
I'm trying to understand the behavior of exceptions in c++. I wrote the following
I am trying to understand the following behavior of shared libraries in C Machine
I'm trying to understand an estrange behavior in Python. I have the next python
I'm trying to understand the behavior of the fields pragma, which I find poorly
I'm trying to understand exact C++ (pre C++0x) behavior with regards to references and
I was trying a program to understand the behavior of structure variable, Sample code:
I am trying to understand this behavior. It's definitely not what I expect. I

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.