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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:14:38+00:00 2026-06-19T03:14:38+00:00

I saw the link http://pvtridvs.net/pool/bithacks.html#BitReverseObvious and posted the code here: unsigned int v; //

  • 0

I saw the link http://pvtridvs.net/pool/bithacks.html#BitReverseObvious and posted the code here:

unsigned int v;         // reverse the bits in this
unsigned int t = v;     // t will have the reversed bits of v
int i;

for (i = sizeof(v) * 8 - 1; i; i--)
{
  t <<= 1;
  v >>= 1;
  t |= v & 1;
}

Would someone explain a little bit why this look-simple algorithm works? I tested on paper some of the simplest examples, say 4-bit 0011 etc, it works, but I simply do not understand why these 3 lines of shift and bit-wise op can achieve it.

  • 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-06-19T03:14:40+00:00Added an answer on June 19, 2026 at 3:14 am

    It shifts bits “out” of the low positions of v and “in” to the low positions of t. Think of the variables as stacks of bits. You’re popping bits from v and pushing them into t. Popping from one list and pushing onto another initially empty list is a simple way to reverse any list. The intialization just performs the initial “push” of the lowest order bit onto the result. This trick saves one pup and push (i.e. a right and left shift). E.g. for a byte, only 7 more pop-pushes are needed.

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

Sidebar

Related Questions

I saw the following drop-up menu example: http://jsfiddle.net/W5FWW/360/ html: <div id=menu> <ul> <li><center><a href=#>Home</a></center>
I saw a link http://dangercove.github.com/html5-notifications/ . Here plain-text-type notification works in google chrome (version
I was pretty surprised when i saw http://www.vorbis.com/music/Hydrate-Kenny_Beltrey.ogg link not give me a download
I saw some code when studying the open source project: here . But I
Website test page: http://www.lantiis.com/indexold.html jsFiddle: http://jsfiddle.net/Guhb4/7/ I received help with the jQuery and it
I saw this link here: How to detect Facebook share success? with Javascript But
I just saw the following code among the successful submissions at codechef. http://www.codechef.com/viewplaintext/1595846 I
If you check this link http://jsfiddle.net/Hbkdt/ . $(window).scroll(function() { $(.fixed).css(top, $(window).scrollTop() + px); });
I saw this link (http://stackoverflow.com/questions/6603868/android-onclicklistener-and-table-layout) which seems like it works for the person asking
I was reading this link http://addyosmani.com/largescalejavascript/#modpattern And saw the following example. var basketModule =

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.