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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:51:56+00:00 2026-05-16T06:51:56+00:00

I ran into this statement in a piece of code: Int32 medianIndex = colorList.Count

  • 0

I ran into this statement in a piece of code:

Int32 medianIndex = colorList.Count >> 1;

colorList is a list of class System.Drawing.Color.

Now the statement is supposed to retrieve the median index of the list .. like the half point of it .. but I can’t understand how that >> symbol works and how the “1” is supposed to give the median index .. I would appreciate some help :S

  • 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-16T06:51:56+00:00Added an answer on May 16, 2026 at 6:51 am

    The >> operator performs a bit shift.

    The expression >> 1 is almost* the same as / 2 so the programmer was calculating the index colorList.Count / 2 which is** the median. To understand why this is the case you need to look at the binary representation of the numbers involved. For example if you have 25 elements in your list:

    n     : 0 0 0 1 1 0 0 1 = 25
             \ \ \ \ \ \ \
    n >> 1: 0 0 0 0 1 1 0 0 = 12
    

    In general using a bitwise operator when really you want to perform a division is a bad practice. It is probably a premature optimization made because the programmer thought it would be faster to perform a bitwise operation instead of a division. It would be much clearer to write a division and I wouldn’t be surprised if the performance of the two approaches is comparable.

    *The expression x >> 1 gives the same result as x / 2 for all positive integers and all negative even integers. However it gives a different result for negative odd integers. For example -101 >> 1 == -51 whereas -101 / 2 == -50.

    **Actually the median is only defined this way if the list has an odd number of elements. For an even number of elements this method will strictly speaking not give the median.

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

Sidebar

Related Questions

I just ran into this piece of code that does this : delete a,
I'm new in python, and just ran into this statement data = dict( (k,
I ran into this error when building my code with CLANG: In file included
Cheers, I ran into this chunk of code in Programming Game AI by Example:
Premise I recently ran into a bug in a select statement in my code.
When trying to create this linq statement. I ran into the following error: Unable
So I recently ran into this C# statement at work: public new string SomeFunction(int
I am learning about the MySQL statement, ORDER BY . I ran into this
Ran into this error message while trying to select some records off a table.
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {

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.