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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:24:20+00:00 2026-06-16T18:24:20+00:00

Possible Duplicate: Converting decimal to binary in Java I have found this code that

  • 0

Possible Duplicate:
Converting decimal to binary in Java

I have found this code that takes as an input a number x, an array p and another number pmax which indicates the size of the array p

public static int permute(int x, int p[], int pmax) {
    int y = 0;

    for (int i = 0; i < p.length; ++i) {
        y <<= 1;
        y |= (x >> (pmax - p[i])) & 1;
    }

    return y;
}

this code should be permutating the bits of the first byte that is stored in the number x
according to the rules defined in the array p

so for example if the first pmax bits of x are 101 and the array p is the following:
p={2 1 3}
then the result of this function(y) will be equal to 011

Question

I have never worked with bitwise operators and I would like to see all the intermediate results of the above code. For example what does y<<=1 do and why it is used. To do this I need to somewhat display the y variable in the binary form, otherwise I just get some random decimals which doesn’t help me understand anything.

So how can I display after each bitwise operation the result in binary format?

If this is not a good method to learn exactly what this code does, what method would you suggest?

  • 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-16T18:24:21+00:00Added an answer on June 16, 2026 at 6:24 pm

    Integer.toBinaryString(int x) will do this for you.

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

Sidebar

Related Questions

Possible Duplicate: Byte array in objective-c Am converting some Java code to Objective-C and
Possible Duplicate: Converting any object to a byte array in java I have a
Possible Duplicate: Porting a C array declaration to Delphi I'm converting a C code
Possible Duplicate: Converting char array into byte array and back again I have a
Possible Duplicate: Converting ereg expressions to preg I have this ereg() expression: ^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$ How
Possible Duplicate: Converting ereg expressions to preg I've tried this a number of different
Possible Duplicate: Converting binary to decimal without using loop I'm looking for the simplest
Possible Duplicate: Converting string of 1s and 0s into binary value Lets say that
Possible Duplicate: converting C to C# i have problem in converting by c code
Possible Duplicate: Converting HTML files to PDF I have HTML in java string and

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.