Binary Number Permutation algorithm?

Hi guys, I want to find all the permutations of a binary number, for example 00001111 . does anyone have some algorithm to do this ? ( without allowing duplicates of course... that's why it's binary anyway )
Any help would be awesome.

That'll work but it's rather slow. This algorithm will generate all r-element subsets of [n] in colex order in time O(n^r O(P(\log n))) and space O(r O(P(\log n))):
1) the first set in the sequence is {1,...,r}
2) given a set S={x[1],...,x[r]} with x[1] < ... < x[r]:
- if S={n-(r-1),...,n}, this is the last set in the sequence;
- otherwise, if x[i1]=x1 for i=1,...,j-1 (j>=1) and x[j+1] >= x[j]+2, the next r-element subset of [n] in the sequence is {1,...,j-1,x[j]1,x[j+1],x[j2],...,x[r]}
Generate the r-element subsets of [n] and then or the corresponding bits to get your binary numbers.

Similar Messages

  • Same pseudo random binary number on two different laptops

    I want to generate same pseudo random binary number on two different laptops at the same time.
    How can I do that. Please provide suggestions.  
    JK

    Hi Joseph,
    I don't have any examples of this. Usually you use PRNGs to generate unique numbers…
    You need to create your own algorithm.
    There are USB sticks available that generate unique numbers in a certain reproducable way, which are used for authentification of bank account operations. You might take them as inspiration for your task…
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Converting a binary number to a list of integers

    I need to convert a binary number to a list of the values of the bit possitions that make up that number. I.e. 1 = 1; 3=2,1; 7=1,2,4.
    Does anyone know of Java API functions that could accomplish this, I couldn't find any, or a function that can do this?

    This reminds me of my programming homework assignments...
    There are some very efficient ways to do this - but I can't remember them off the top of my head. I can guarantee they will have been posted several hundred times before. This will work:
    class BitMask {
        private byte mask = 1;
        public void printBitFields(int a) {
         System.out.print(a + " =");
         for(i = 0 ; (a & Integer.MAX_VALUE) != 0 ; i++) {
             if((a & mask) == 1)
              System.out.print(" " + ((int) java.lang.Math.pow(2,i)));
             a >>= 1;
         System.out.println();
        public final static void main(String args[]) {
         BitMask bm = new BitMask();
         bm.print(1);
         bm.print(18);
         bm.print(19); // etc...
    }

  • How to transmit binary number by using USRP example QAM TX

    Hello:  now my project is build up a wireless communication system by using QAM,there is one really good example in the modulation toolkit,but what should I do if I want to know exactly the message I am transmitting for example binary number?Which part should I modify in the example?Thanks.

    See this example:  Packet Based Digital Link  https://decibel.ni.com/content/docs/DOC-18801

  • Append each bit to the binary number (Not Array Indicator)

    Hi All
    If i have the 8 Number control. Each Control represent each bit.
    i.e. 0th control bit="1", 1th control bit="0", other bit = "0"....7th control bit ="1".
    How to output the 1 binary number indicator. -->10000001
    Thanks
    Best Regards,
    Steve

    I had solved it.
    i use true/false case to multiply each bit interial.
    i.e. For 8 th bit. If =0, output to 0, if =1 (i.e not equal to 0), output 10000000
          For 7 th bit. If =0, output to 0, if =1 (i.e not equal to 0), output 1000000
    Final, use "OR" function to build into 1 binary number.
    Please refer the attached graph.
    Anyway, have the other fast way to do this result??
    Thanks
    Steve
    Attachments:
    Each Bit to build-in 1 indicator.jpg ‏71 KB

  • About binary number and decimal number?

    how to use a class to convert a decimal number from a binary number?Thank you

    You've already asked the same kind of thing before (http://forum.java.sun.com/thread.jsp?forum=31&thread=325249), and fsato4 answered. Here is the same thing, but decimal to binary.
    public class ToBinary {
         public static void main(String[] args) {
              int n = 12; 
              System.out.println(Integer.toString(n)); 
              System.out.println(Integer.toBinaryString(n));

  • Add leading 0's to binary number

    hi,
    i am learing labview and i wanted to do something like this..
    i want to read in a text file.
    convert the decimal numbers to binary numbers
    and then add leading zeros if the lenght of the binary is less than X number.
    and then ultimately sum up all binary numbers and parse it into 1 bits as 1 array.
    the reason for me doing this because i am generating a singal.
    i have started on this, but i am stuck at the comments, can someone help me out. 
    thank you in advance..
    Message Edited by Giangliang on 04-02-2009 06:54 PM
    Solved!
    Go to Solution.
    Attachments:
    Array_v4.vi ‏45 KB
    example.txt ‏3 KB

    Can you show us your final version? Your v6 is sitll an absolute mess.
    Most of your code is very inadequate and overly complicated. None of your shift registers make any sense, you can delete the (1) shift registers, (2) index array, (3) insert into array (4) initialize array, etc. and replace all with two simple autoindexing tunnels.
    I still don't quite understand what you need, but my best guess is that it can be done with code the size of a postage stamp.
    To count the number of "1" bits in an array of numeric intergers, you can use e.g. a 16 bit lookup table, no strings or formatting operations needed. It will be many orders of magnitude faster and simpler. All you need is blue wires.
    Please show us the final version that gives the correct and desired result so we can show you how to do this right.
    LabVIEW Champion . Do more with less code and in less time .

  • Photo number sorting algorithm

    if there are millions of phone numbers that need to be sorted, does anybody know if there is a most proper algorithm out there?
    I have been searching, but can't find a good one.
    Thanks.

    If you use any reasonable algorithm your millions of phone numbers will be sorted in less time than it takes to read this reply. Perhaps the real question is why are you sorting those numbers over and over and over so that choice of algorithm matters in the slightest. Sort them once and keep them sorted.

  • Binary number to decimal

    Hi
    I realy need help with my java program because something is built wrong and is does not working properly.
    I attached my program:
    import java.util.Scanner;
    import java.lang.*;
    public class BinaryToDecimal {
    public static void main (String [] args) {
    String a;
    int b;
    double sum;
    Scanner reader=new Scanner(System.in);
    System.out.println("Enter a binary String: \t");
    String binary=reader.nextLine();
    sum = 0;
    for (int i = 0; i < binary.length(); i++) {
    a = Character.toString(binary.charAt(binary.length() - i -1));
    sum = sum + Integer.parseInt(a) * Math.pow(2, i);
    System.out.println(sum);
    If somebody can check this because the output is wrong

    1) When you post code, use the CODE button or [code and [/code] tags.
    2) Define "not working."
    3) Do you have to write this method yourself? If not, look at the docs for java.lang.Integer.
    4) Print out sum inside the loop so you can see what's happening each time. Also print out other variables, the results of intermediate calculations, etc., so you can see which code is being executed, how many times, and what it's doing.

  • Number crunching algorithm

    I've run into a programming challenge that involves number crunching and I'm stumped on an equation. Here's what I have that works so far:
    double y = (Math.sqrt(x) - 1/x) / 2;It basically takes x as a given and computes y, producing a 2D curve. Where I'm stumped is I want to take y as a given and compute x to produce the identical curve. Is this possible? I've managed to reformulate the equation several different ways on paper, but haven't arrived at anything useful. (I'm kind of rusty on algebra.) Any help on how to go about this would be appreciated.

    I've run into a programming challenge that involves
    number crunching and I'm stumped on an equation.
    Here's what I have that works so far:
    double y = (Math.sqrt(x) - 1/x) / 2;It basically takes x as a given and computes y,
    producing a 2D curve. Where I'm stumped is I want to
    take y as a given and compute x to produce the
    identical curve. Is this possible? I've managed to
    reformulate the equation several different ways on
    paper, but haven't arrived at anything useful. (I'm
    kind of rusty on algebra.) Any help on how to go about
    this would be appreciated.let a = sqr(x), and rewrite your function:
    y = (a- 1/a^2)/2
    simple above, you get
    2y = a - (1/a^2)
    then
    a = 2y + 1/a^2
    then
    a = ((2a^2)*y + 1)/a^2
    then
    a^3 = (2a^2)*y + 1
    then
    (2a^2)*y = a^3 - 1
    therefore
    y = (a^3 - 1)/2a^2
    then substitute sqr(x) back, you get
    y = (sqr(x)-1)/2
    hmm...hope I have done everything correctly....

  • Vi to change binary number

    I need to create a Vi to change the 8 bits of a word as follow:
     x18 = 00011000 and need to change to (xC0) 11000000 (the 3 firt bit nee to changed to final) now is
     xF4 = 11110100 and needto change to (xA7) 10100111
    Thank you guys

    Here's a quick exmple
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    rotate3.png ‏10 KB

  • Program to convert binary to decimal number?

    I only know how to do a program that converts only 4 numbers, but it to convert any amount of digits the number enters, I think you need to use a loop or something, but I'm not sure how. Could someone please help me? This is my code so far:
    import javax.swing.JOptionPane;
    public class bintodec {
         public static void main (String[] args) {
              String input;
              int number,digit1,digit2,digit3,digit4,result;
              input = JOptionPane.showInputDialog ("Enter a binary number.");
              number = Integer.parseInt(input);
              digit1 = ((number % 10000) - (number % 10000 % 1000)) / 1000;
              digit2 = ((number % 1000) - (number % 1000 % 100)) / 100;
              digit3 = ((number % 100) - (number % 100 % 10)) / 10;
              digit4 = (number % 10);
              result = (digit1 * 8) + (digit2 * 4) + (digit3 * 2) + (digit4 * 1);
              System.out.println ( "Binary number: " + input + "\nConverted Decimal Number: " + result);
              System.exit( 0 );
         } // main
    } // bintodecany help is super-appreciated.

    I am not sure if this will help you. Check it out, run it and let me know if it helped.
    import java.util.*;
       public class BitwiseTest1 {
           public static void main(String[] args){
            System.out.println("Enter a integer number:");
            Scanner keyboard = new Scanner(System.in);
            int n1 = keyboard.nextInt();
            System.out.println( "n1 as binary " +
                   Integer.toBinaryString( n1 ));
            System.out.println( "NOT n1 =     " +
                   Integer.toBinaryString( ~n1 ));
            System.out.println("Enter another integer number:");
            int n2 = keyboard.nextInt();
            System.out.println( "n2 as binary " +
                   Integer.toBinaryString( n2 ));
             System.out.println( "NOT n2 =     " +
                   Integer.toBinaryString( ~n2 ));
    }

  • Binary or number string

    Hi...
    How can I know if a string is a binary or number?
    thank you.

    You can only test for a String not containing a binary number like this..
    boolean isNotBinary = ( someString.indexOf( "0" ) == -1 && someString.indexOf( "1 ) == -1 );As a number can be anything with "-012345678eE." and has to adhere to a specific format to qualify as a number AND the fact that the radix makes everything ambiguous determining if a String contains a number and is binary becomes horribly complicated.
    Your definition of number needs to be more tightly defined, integer/long, float/double, fixed decimal and integer/long numbers with different radix need to be considered before you can test for numberness.

  • Operations on very large binary numbers

    Hi guys,
    I'm trying to write a java class for manipulations of very large binary numbers.
    I'm representing the BN internally as boolean[] (array of booleans false for 0 & true for 1).
    I want to write an algorithm for the following operations :
    shifLeft (boolean[] b,int n) : shifting binary number to left by n positions.preferably a circular shift .
    and also the corresponding shiftRight() method.
    can some one guide me on how to implement this ?
    thanks.

    Consider an array of ascii chars....
    array =>   | |a|b|c|d|
    offset = 1
    len = 4In the above there are actually five spots in the
    array but the offset points to the second position in
    the array and the length is 4.
    If I was to extract the value it would be "abcd"
    because of the offset and the length.
    Now a 'shift right' means that if it is "abcd" then
    it should now be "abc" (because the d fell off the
    end.)
    I can do that like this.
    array =>   | |a|b|c|d|
    offset = 1
    len = 3Notice in the above that nothing changed except the
    length. But because the length changed if I
    extracted the value I would get "abc" because the
    offset is 1 and the length is three.
    Notice also that there was no array copying.Are you sure shifting works like that ?
    what I know about left shifting is that the 'd' should be moved left -toghether with a, b, c- and we append a 0 in place of 'd' .
    from what you said the 'd' would be gone , or am I again wrong ?
    it seems i still didn't get any satisfactory answer to this problem...

  • Decimal to binary conversion

    hi...anyone here knows the code to convert decimal to binary.Please help me!!!

    Here's the answer in a riddle - to fill in the blank line is to understand the algorithm used - have fun!
    class BinaryConverter{
       public static void main(String []args) throws Error{
          try{
             new BinaryConverter(Integer.parseInt(args[0]));
          }catch(ArrayIndexOutOfBoundsException e){
             System.out.println("No argument entered");
          } catch(NumberFormatException e){
             System.out.println("Enter whole numbers only");
       private BinaryConverter(int i){
          System.out.println("The binary number is: ");          
          convert(i, 0, (long)Math.pow(2, 31));
       private void convert(int num, int i, long max){
          if(num / max==1) System.out.print("1");
          else System.out.print("0");
          num %= max;
          // there is a line deliberately removed here!
          if(i++ % 8 ==0) System.out.print(" ");
          if(max >0) convert(num, i, max);
    }

Maybe you are looking for

  • CSS and Compression:Disable the CSS Compression in WebCenter Spaces

    Hi, I follow exactely all recommandations that i had seen in different website. I add in my web.xml for MyCustomWebcenterSpacesWAR <context-param> <param-name> org.apache.myfaces.trinidad.DISABLE_CONTENT_COMPRESSION </param-name> <param-value> true <

  • Replace/manage color

    I hope someone can help me. I have a document with an imported logo. The logo has one color, supposed to be PMS 267-C. The document has two colors of text, PMS 267-C and black. Can I convert process to spot in InDesign for the document so that it pri

  • PUSH-BUTTON in ALV GRID

    How can we create a push-button in ALV-GRID. How will u handle a push-button in ALV.

  • How to change the artwork of a video file???

    is it possible to change the artwork of a video file. sometimes it comes up with its own artwork, and others there is just a black screen.... Thanks in advance

  • Replacement for FM

    Hi, Can anyone tell me the replacement for the FM 'C1F2_SUBSTANCES_READ'. We are upgrading to E.C.C 6.0 version. Regards, Swathi