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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:59:13+00:00 2026-05-30T15:59:13+00:00

Here is the implementation of reverse in Long: public static long reverse(long i) {

  • 0

Here is the implementation of reverse in Long:

public static long reverse(long i) {
        // HD, Figure 7-1
    i = (i & 0x5555555555555555L) << 1 | (i >>> 1) & 0x5555555555555555L;//1
    i = (i & 0x3333333333333333L) << 2 | (i >>> 2) & 0x3333333333333333L;//2
    i = (i & 0x0f0f0f0f0f0f0f0fL) << 4 | (i >>> 4) & 0x0f0f0f0f0f0f0f0fL;//3
    i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;//4
    i = (i << 48) | ((i & 0xffff0000L) << 16) |
        ((i >>> 16) & 0xffff0000L) | (i >>> 48);//5
    return i;
}

I can understand line 1,2,3,4, but not 5! How does it work?

I group the 64 bits to 8 groups,that is 1 is the first 8 bits, 2 is the second 8 bits, and so on.

Then after line 4,the sequence like 4,3,2,1,8,7,6,5

and I think line 5 working as below before the | operation:

6,5,0,0,0,0,0,0-->(i << 48)
8,7,0,0,0,0,0,0-->((i & 0xffff0000L) << 16)
0,0,0,0,4,3,2,1-->((i >>> 16) & 0xffff0000L)
0,0,0,0,0,0,2,1-->(i >>> 48)

But, I don’t know where dose it wrong or whether it is wrong! Thinking about it almost about a whole day!

Somebody can help me!! Thanks.

oh, i made a mistake like this:

6,5,0,0,0,0,0,0-->(i << 48)
0,0,8,7,0,0,0,0-->((i & 0xffff0000L) << 16)
0,0,0,0,2,1,0,0-->((i >>> 16) & 0xffff0000L)
0,0,0,0,0,0,4,3-->(i >>> 48)

but i alse think it is wrong! i think the right sequence is 8,7,6,5,4,3,2,1

i am so sorry that i make some mistakes! it works right as below:

after line 4, the right pattern is:2,1,4,3,6,5,8,7

8,7,0,0,0,0,0,0-->(i << 48)
0,0,6,5,0,0,0,0-->((i & 0xffff0000L) << 16)
0,0,0,0,4,3,0,0-->((i >>> 16) & 0xffff0000L)
0,0,0,0,0,0,2,1-->(i >>> 48)
  • 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-30T15:59:14+00:00Added an answer on May 30, 2026 at 3:59 pm

    Line 1 swaps adjacent single bits in pairs (0 <-> 1; 2 <-> 3; etc.). Lines 2-4 swaps adjacent sequences of two bits, 4 bits, and 8 bits. At that point, the original value has been transformed into four blocks of 16 bits with each block the reverse of what it had been at the start. Line 5 then rearranges the 4 blocks. Basically, line 5 combines two steps into one: swapping two pairs of 16-bit blocks and swapping one pair of 32-bit blocks. The logic is:

    • (i << 48) moves the rightmost 16-bit block to the left position, leaving all other bits zero
    • ((i & 0xffff0000L) << 16) moves the second block from the right to be the second block from the left (all other bits zero)
    • ((i >>> 16) & 0xffff0000L) moves the second block from the left to be the second block from the right (all other bits zero)
    • (i >>> 48) moves the leftmost block to the right position (all other bits zero)

    Then these four values are |-ed together to produce the final reversal. If it had been done in two steps, it would be two statements that look just like the first four statements, but with different mask patterns.

    I think that after line 4, the pattern is 2,1,4,3,6,5,8,7, not 4,3,2,1,8,7,6,5 as you assumed. The four pieces of line 5 then are:

    8,7,0,0,0,0,0,0-->(i << 48)
    0,0,6,5,0,0,0,0-->((i & 0xffff0000L) << 16)
    0,0,0,0,4,3,0,0-->((i >>> 16) & 0xffff0000L)
    0,0,0,0,0,0,2,1-->(i >>> 48)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code : @implementation Accumulateur // Constructor - (id) init { return
Here's a Clone() implementation for my class: MyClass^ Clone(){ return gcnew MyClass(this->member1, this->member2); }
Here is my implementation in summary 1) all DAOs implemented using HibernateDAO support/ @Transational
Here's the implementation of java.lang.reflect.Method.equals(Object obj) as of Java 7: /** * Compares this
I'm having some difficulties getting the TabActivity to work. Here's the implementation of the
Here is the hashCode() implementation from Java HashTable Class. What if the number of
Here is my perceptron implementation in ANSI C: #include <stdio.h> #include <stdlib.h> #include <math.h>
here is my code for xor linked list implementation #include<iostream> using namespace std; struct
Here is a very basic class for handling sessions on App Engine: Lightweight implementation
Here's a question that comes up again and again in C++ class implementation. I'm

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.