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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:43:45+00:00 2026-05-25T10:43:45+00:00

1. Consider the following: unsigned int a, b; b = a >> ((sizeof a)

  • 0

1.
Consider the following:

unsigned int a, b;

b = a >> ((sizeof a) * CHAR_BIT);

/* or 2nd operand greater than ((sizeof a) * CHAR_BIT) */

Is this is defined, undefined behavior or implementation dependent behavior?

2.
Also another sub-question:

In the case a is signed int and it is shifted less than its bit length, is the signed bit shifting implementation defined or undefined behavior. In both the cases:

  1. When shifting right : a >> 5
  2. When shifting left : a << 5

EDIT question edited

  • 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-25T10:43:46+00:00Added an answer on May 25, 2026 at 10:43 am

    1.

    From C99 standard, section 6.5.7:

    The integer promotions are performed on each of the operands. The type of the result is
    that of the promoted left operand. If the value of the right operand is negative or is
    greater than or equal to the width of the promoted left operand, the behavior is undefined.

    So it’s undefined.

    2.

    From the same section:

    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 x 2E2, reduced modulo one more than the maximum value representable in the result type. If E1 has a signed type and nonnegative value, and E1 x 2E2 is representable in the result type, then that is the resulting value; otherwise, the behavior is undefined.

    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 / 2E2. If E1 has a signed type and a negative value, the resulting value is implementation-defined.

    So for left-shift, it’s well-defined if a is signed and positive. It’s undefined if a is signed and negative.

    For right-shift, it’s well-defined if a is signed and positive. It’s implementation-defined if a is signed and negative.

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

Sidebar

Related Questions

Consider the following non-working code: typedef map<int, unsigned> mymap; mymap m; for( int i
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
Consider the following code template<unsigned int N> void foo(std::bitset<N> bs) { /* whatever */
Consider the following C program: #include <stdio.h> int main(){ int a =-1; unsigned b=-1;
Consider the following SQL: CREATE TABLE USER1 ( pkUSER1_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
Background Consider the following: template <unsigned N> struct Fibonacci { enum { value =
Consider following class class test { public: test(int x){ cout<< test \n; } };
Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider the following situation: class MyFoo { public: MyFoo(); ~MyFoo(); void doSomething(void); private: unsigned
Consider I have Struct like the following: struct Bitmask { unsigned char payload_length: 7;

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.