Jump to content

How to find the nth binary permutation?

Featured Replies

This is the last missing piece I need to complete my compression algorithm, new one. Let's say I have 4 bits with 2 bits set as 1, 0011. The total number of permutations for this number is 0011, 0101, 0110, 1001, 1010, 1100, 6 cases. This can be computed using the calculation.

 

4! / ((2!)(4-2)!) = 6

 

Now I want to be able to find the nth sequence, for instance 1st number is 0011, second number is 0101. So if I say n=5, I want to be able to get the 5th permutation sequence 1010 from the initial 0011. How do I do this?

You need to define how the permutations are ordered. Permutations give you a total, but they can be in any order.

  • Author

Right as I've mentioned I want 0011 to be 1, so having all the one bits on the right as 1, then slowly move to the left. It really doesn't matter as long as I can track the sequence in an orderly fashion. So I want to be able to derive a sequence using the nth value. For instance I want n=5 to get me 1010 in this case

 

P.S. We know how we can get any binary order using 2 to the power, for instance if I have n=15 I would get 15-2^3-2^2-2^1-2^0 and get 1111

Edited by fredreload

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.