hi
can you please help me with this problem?
i am trying to generate all combinations of binary number with fix number of digits and number of ones
e.g. number of digits=4 and number of ones=2:
0011
0101
0110
1001
1010
1100
have you got any idea how to solve this?
thanks a lot
binary number combination
Started by gor, Feb 26 2008 12:19 AM
6 replies to this topic
#1
Posted 26 February 2008 - 12:19 AM
|
|
|
#2
Posted 26 February 2008 - 03:16 AM
What language do you want to do this in? This is both a Python and Delphi forum. Kinda odd, now when I'm thinking of it. Maybe Jordan could change it?
Use your favorite search engine for searching on:
"Python permutations"
or, if you're using Delphi:
"Delphi permutations"
Use your favorite search engine for searching on:
"Python permutations"
or, if you're using Delphi:
"Delphi permutations"
#3
Posted 26 February 2008 - 03:23 AM
v0id said:
What language do you want to do this in?
but this is more question about algorithms
#4
Posted 26 February 2008 - 04:49 AM
Indeed it is, but if you searched on Google using the keywords I said, you would be able to find pages which both covers Delphi and permutations.
If you want information purely about the algorithm itself, then you should check out Wikipedia's article on permutation.
If you want information purely about the algorithm itself, then you should check out Wikipedia's article on permutation.
#5
Posted 26 February 2008 - 09:24 AM
One way to approach it:
Have a for loop from 0 to 2^digits -1.
For each value, do a bitwise and against 1,2,4,8,etc, counting the number of results that are 1. Sum the results (to count the number of 1's) and also concatenate the IntToStrings of the results(to build a string to display). If the sum is 2, then print the string.
Have a for loop from 0 to 2^digits -1.
For each value, do a bitwise and against 1,2,4,8,etc, counting the number of results that are 1. Sum the results (to count the number of 1's) and also concatenate the IntToStrings of the results(to build a string to display). If the sum is 2, then print the string.
#6
Posted 30 March 2009 - 04:22 AM
hi...
im a student doing turbo pascal at skool in australia.
i have been given the task to create a program in turbo which converts decimal numbers inputted by the user to 7 bit binary numbers with odd parity, and convert inputted 8 bit binary numbers to decimal...
can anyone help me with this...
i cant seem to find anything on the internet involving algorithms or source code to do the required things... and i downright suck at coding...
plz help me...
im a student doing turbo pascal at skool in australia.
i have been given the task to create a program in turbo which converts decimal numbers inputted by the user to 7 bit binary numbers with odd parity, and convert inputted 8 bit binary numbers to decimal...
can anyone help me with this...
i cant seem to find anything on the internet involving algorithms or source code to do the required things... and i downright suck at coding...
plz help me...
#7
Posted 30 March 2009 - 07:54 AM


Sign In
Create Account


Back to top









