08-01-2011 10:47 AM
I want to allow user to program 8th,7th and 6th MSB bits of a 16-bit word while other bits in word remain fixed. Let's say for a word "1111111XXX111111" the value of bits represented by X will be decided by what user enters in control. How to do it?
Solved! Go to Solution.
08-01-2011 11:45 AM
08-01-2011 12:39 PM - edited 08-01-2011 12:40 PM
Why the arrays? Embrace Boolean logic!
08-01-2011 12:40 PM - edited 08-01-2011 12:43 PM
Usually boolean operations will be simpler.
If you want to turn on bits, AND them with a constant that has those bits set to 1 and all others set to 0.
If you want to turn off bits, AND them with a constant that has those bits set to 0 and all others set to 1.
If you want to toggle bits, XOR them with a constant that has those bits set to 1 and all others set to 0.
If you need to set them to some arbitrary series of 1's and 0's no matter what the current state of the number is, then use Jcarmody's array manipulation method. Alternatively, AND those bits with a constant where they are set to 0 (all others set to 1), then AND it with the arbitrary series of bits (and all others set to 0.)
EDIT: I like Smercurio's manipulations even better.
08-01-2011 12:45 PM
Hey Smercurio_fc, your way looks quite easy , can you upload vi pls so i can try it...thx
08-01-2011 12:46 PM
Thx jcarmody, giving me a way out for this.
08-01-2011 12:47 PM
His is a VI snippet. Just drag the image from your browser into a block diagram.
08-01-2011 01:00 PM
@smercurio_fc wrote:
Why the arrays? Embrace Boolean logic!
That's what I first thought, but it only works one way.
08-01-2011 01:13 PM - edited 08-01-2011 01:15 PM
I went by the original statement of the problem, which had ones. If you want a more generic solution, that's a simple modification (still with no arrays )
08-01-2011 01:17 PM - edited 08-01-2011 01:17 PM
Follow-up:
You can eliminate the 0x00E0 constant by wiring the second input of the top OR to a NOT: