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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:35:02+00:00 2026-05-17T23:35:02+00:00

I watched a video today and the guy in the video just write this

  • 0

I watched a video today and the guy in the video just write this to understand whether a number is even or not:

number/2*2 == number ? true : false ; 

i tried it when i got home and compared with

number % 2 == 0 ? true : false ; 

The second one was faster then i changed the first one as:

number>>1<<1 == number ? true : false; 

this time shifting the number once to the right and once to left worked faster 😀
The performance difference is not huge just 0-1 second for identifying all the numbers
between 1 and 1000000000 but I liked it very much and wanted to hear such tricks from you.

so what else ? =)

and another idea from Russell Borogove =)

(number&1) == 0;

Results:

Time Elapsed With And Operation:00:00:07.0504033
Time Elapsed With Shift Operation:00:00:06.4653698
Time Elapsed With Mod Operation:00:00:06.8323908

Surprisingly shifting two times is working faster than a single and operation on my computer.

  • 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-17T23:35:03+00:00Added an answer on May 17, 2026 at 11:35 pm

    MIT actually keeps a list of such things, HAKMEM, which can be found at http://www.inwap.com/pdp10/hbaker/hakmem/hakmem.html. Most of the programming-related ones are written in assembly language, but I understand that some of them have been translated to C at http://graphics.stanford.edu/~seander/bithacks.html.

    Now for a lecture: These dirty tricks might be faster, but take far too long to comprehend.

    Most computing isn’t so performance-critical that tricks like this are necessary. In the odd-even case, number % 2 == 0 is much clearer and more readable than number/2*2 == number or number>>1<<1 == number. That said, in normal applications you should always use the simpler and more standard option because it will make your code easier to understand and maintain.

    However, there are use cases for tricks like this. Especially in large-scale mathematical or scientific computing and computer graphics, tricks like these can save your life. An excellent example of this is John Carmack’s “magic inverse square root” in Quake 3.

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

Sidebar

Related Questions

I've just watched this video showing off an app: https://www.youtube.com/watch?v=2qM3Zps_0pE&feature=player_embedded At 3:34. How in
I just watched the following video: Introduction to Node.js and still don't understand how
I just watched a video where they used Viterbi algorithm to determine whether certain
I've watched this video from Google I/O 2009: http://www.youtube.com/watch?v=AgaL6NGpkB8 where Brett shows microblogging example.
I've read this question mentioning Code Bubbles and I've watched their video presentation. The
This is my first step to programming.guys your help hands required.I watched youtube video
I watched this video . Why is a = a evaluated to nil if
I just watched a video of Douglas Crockford's presentation about his 2009 book JavaScript:
After I watched this NetTUTs video , I'm very interested in trying out the
I just watched a video regarding the Report Designer. It said to go to

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.