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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:44:43+00:00 2026-05-21T22:44:43+00:00

I underestimated the complexity of the >> operator; it’s not doing what I thought

  • 0

I underestimated the complexity of the >> operator; it’s not doing what I thought it would.

I want to right shift a uint value of 6542454. I thought it worked like this:

val (is) == 11000111101010001110110
val >> 1 == 1100011110101000111011
val >> 2 == 110001111010100011101
val >> 3 == 11000111101010001110
val >> 4 == 1100011110101000111
val >> 5 == 110001111010100011
val >> 6 == 11000111101010001
val >> 7 == 1100011110101000

In reality, the results are:

val >> 1 == 1100011110101000111011
val >> 2 == 110001111010100011101
val >> 3 == 11111001100100110010011
val >> 4 == 1111100110010011001001
val >> 5 == 111110011001001100100
val >> 6 == 11111001100100110010
val >> 7 == 10011011111110111111100

The 3rd operation clearly does something I don’t understand and things go off the rails from there. Seems to do the thing I don’t understand again at the 7th operation as well.

Using the >>= operator 7 times in a row yields values I would expect:

val >>= 1 == 1100011110101000111011
val >>= 1 == 110001111010100011101
val >>= 1 == 11000111101010001110
val >>= 1 == 1100011110101000111
val >>= 1 == 110001111010100011
val >>= 1 == 11000111101010001
val >>= 1 == 1100011110101000

Why does val >> 3 not yield the same result as 3 calls to val >>= 1?

UPDATE:

My fault for using a decimal to binary converter on the web that was truncating my decimal input to 7 digits. When copy + pasting decimal values from Visual Studio, I didn’t notice the truncation occurring.

The actual value being shifted is 654245426 and as everyone is correctly pointing out, C# is bit-shifting this value perfectly.

  • 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-21T22:44:44+00:00Added an answer on May 21, 2026 at 10:44 pm

    I wrote code to output each shift:

    uint i = 6542454;
    
    for (int j = 0; j < 8; j++)
    {
        uint k = i >> j;
        Console.WriteLine("{1} = {0}", Convert.ToString(k, 2), k);
    }
    

    and this is what I would expect to and did see.

    6542454 = 11000111101010001110110
    3271227 = 1100011110101000111011
    1635613 = 110001111010100011101
    817806 = 11000111101010001110
    408903 = 1100011110101000111
    204451 = 110001111010100011
    102225 = 11000111101010001
    51112 = 1100011110101000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I underestimated the amount of time a job would take. Would it be possible
I have a CLLoctionCoordinate2D and I want to figure out what the points are
Imagine the following scenario: You are asked to develop a tool from scracth, by
I am generating a PDF with fPDF. I need to strikethrough a long text
I'm a student who still doesn't quite get const parameters. I understand why this
I am currently taking a c++ course and trying to get a deep understanding
I am looking for a tool like that excellent one proposed in the accepted
<span class=WorkingHours> M,W,Th,F 7:30 AM - 4:00 PM &lt;br /&gt;Tu 7:30 AM - 6:00
I jsu have small inquiry, and please dont underestimate it. I Have a class
I understand why A* algorithm always gives the most optimal path to a goal

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.