LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generating bits in LabVIEW

Solved!
Go to solution

Hello,

 

Using LabVIEW, I need to generate all bit patterns of length N containing at most ones x ones and N-x zeros, for example if N=4, x=1 and the patterns would be 1000, 0100, 0010, 0001.

 

Thanks in advance.

0 Kudos
Message 1 of 7
(4,111 Views)

This sounds a lot like a homework assignment.

 

Do you need the value as a number of a string of ASCII 0s and 1s? This can easily be done using an array. You would also to initialize the array to the specific size. Use a FOR loop to iterate the number of bits you have and use the base array you created with a replace array to replace the specific bit position.

 

If this is indeed a homework assignment this should give you enough to get a start on it. If it is not an assignment post what you have tried so far and we can go from there.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 7
(4,103 Views)

Firstly, thank you for your reply. Secondly, its not a home work problem, there is huge application behind it, think about generating 32 C 6 combinations using binary digits, (huge number). I would be happy if you are able to give proper answer  rather than commenting like that. 


@Mark Yedinak wrote:

This sounds a lot like a homework assignment.

 

Do you need the value as a number of a string of ASCII 0s and 1s? This can easily be done using an array. You would also to initialize the array to the specific size. Use a FOR loop to iterate the number of bits you have and use the base array you created with a replace array to replace the specific bit position.

 

If this is indeed a homework assignment this should give you enough to get a start on it. If it is not an assignment post what you have tried so far and we can go from there.


 

0 Kudos
Message 3 of 7
(4,080 Views)
Solution
Accepted by topic author ramutha

My usual code to generate permutations with repeated elements adapted to this problem.  I assume you want arrays of 1's and 0's.

 

PermuteBits.vi will generate the next combination in the sequence based on the value of the previous iteration.  Using this method does not require you carry around all of the combinations.

 

GetBitPermutations.vi will retrieve all combinations if that is what you desire.

 

Download All
Message 4 of 7
(4,072 Views)

I apologize if I sounded gruff but i have a policy of not providing solutions to questions that sound like a homework assignment. Your original question sounded very much like that. I also missed the mark on my suggestion in that it would only work for the general case with a single bit set. However, Darin provided a very elegant solution before I could post anything. No need for me to whip something up now.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 7
(4,069 Views)

Thank you very much Darin. It is really a great starting point for our application, I appreciate it.

0 Kudos
Message 6 of 7
(4,042 Views)

Thats ok Mark, No problem, thanks a lot.

0 Kudos
Message 7 of 7
(4,041 Views)