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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:04:10+00:00 2026-05-27T11:04:10+00:00

Possible Duplicate: >> in javascript Here: var num=10; console.log(num/2); num=4; console.log(num/2); It gives me

  • 0

Possible Duplicate:
>> in javascript

Here:

var num=10;
console.log(num/2);
num=4;
console.log(num/2);

It gives me 5 and 2.

And this one:

var num=10;
console.log(num>>1);
num=4;
console.log(num>>1);

It also gives me 5 and 2.
So x/2 is the same as x>>1? But why?

  • 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-27T11:04:10+00:00Added an answer on May 27, 2026 at 11:04 am

    For the same reason that dropping the last digit off a normal (decimal) number is the same as dividing it by 10 (ignoring, of course, any non-integer remainder).

    In computers, integers are internally represented in binary (base 2). So each digit represents a power of 2 instead of a power of 10 that we’re used to with the decimal system.

    >> 1 just means to shift all the bits right by one, which is another way of saying “drop the last digit”. Since the digits are in binary, that’s equivalent to dividing by the base, which is 2.

    Similarly, if you need to divide by any power of 2, you can do so using the right shift operator: To divide by 4, shift by 2; to divide by 8, shift by 3; and so on.

    Note that internally, it’s often more efficient to do a shift operation instead of a division operation, but any compiler worth its salt will do this optimization for you (so that you don’t have to write obfuscated code to get the performance benefit — generally, you would only use the shift operator when your intention is to manipulate bits directly, and use the division operator when your intention is to do math).

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

Sidebar

Related Questions

Possible Duplicate JavaScript: Changing src-attribute of a embed-tag but this is not working for
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the
Possible Duplicate: Javascript: var functionName = function() {} vs function functionName() {} Way 1:
Possible Duplicate: Chaining a function in JavaScript? I asked a similar question , but
Possible Duplicate: Javascript: How to loop through ALL DOM elements on a page? var
Possible Duplicate: How do you pass a variable to a Regular Expression JavaScript? This
Possible Duplicate: Kill Ajax requests using JavaScript using jQuery Here is the simple code
Possible Duplicate: Difference between single quotes and double quotes in Javascript Sorry guys, but
Possible Duplicate: javascript - check if string begins with something? I've read in this
Possible Duplicate: JavaScript: immediate function invocation syntax A similar question has been asked here

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.