-
April 26th, 2008, 05:52 AM
#1
Help With Finding All Combinations for Array length R
Hi,
I am currently working on a program that uses Hamming Codes to encode various incoming arrays of 1's and 0's . However, in order to do this i need to create a Generator matrix which requires that I know all possible combinations for an array of length N (by all combinations i just mean binary 1 and 0)... this is so i can find a basis for set and thus create a Matrix.
Was just wondering... can someone explain to me what the logic is/ how to go about using loops to fill in a 2-D array with all possible combinations of 1's and 0's for any n?
Just for clarification heres what I mean:
say array length is 3:
[1 1 0
1 0 1
0 1 1
1 1 1
1 0 0
0 1 0
0 0 1]
Thanks!
-
April 26th, 2008, 06:19 AM
#2
Re: Help With Finding All Combinations for Array length R
-
April 26th, 2008, 07:44 AM
#3
Re: Help With Finding All Combinations for Array length R
Originally Posted by shahs8
Was just wondering... can someone explain to me what the logic is/ how to go about using loops to fill in a 2-D array with all possible combinations of 1's and 0's for any n?
For an array of length R there are 2^R combinations. The bit combinations are the binary numbers between 0 and (2^R)-1, like
0=000
1=001
2=010
3=011
4=100
5=101
6=110
7=111
So in principle if R=3 the numbers 0 to 7 represent all bit combinations. It means that these numbers are a dense representation of your arrays.
-
April 26th, 2008, 11:24 AM
#4
Re: Help With Finding All Combinations for Array length R
Originally Posted by shahs8
Hi,
Was just wondering... can someone explain to me what the logic is/ how to go about using loops to fill in a 2-D array with all possible combinations of 1's and 0's for any n?
The combinaisons of 1 and 0 of length n is simply the binary representations of all numbers from 0 to (2^n)-1. It should be easy to generate the binary representation of those numbers.
JeffB
Last edited by JeffB; April 26th, 2008 at 11:26 AM.
-
April 26th, 2008, 06:48 PM
#5
Re: Help With Finding All Combinations for Array length R
If you don't want to mess around with bit-shifting or masking, you could have a look at Integer.toBinaryString(..) or Long.toBinaryString().
Any programming problem can be solved by adding a level of indirection...
Anon.
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|