LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Allow programability to few specific bits in a word while other remain fixed

Solved!
Go to solution

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?  

0 Kudos
Message 1 of 14
(2,527 Views)
Solution
Accepted by topic author Labbyte

Convert the numbers into arrays and make your replacements there.

 

Example_VI.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 2 of 14
(2,509 Views)

Why the arrays? Embrace Boolean logic! Smiley Wink

 

 

Message 3 of 14
(2,493 Views)

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.

0 Kudos
Message 4 of 14
(2,491 Views)

Hey Smercurio_fc, your way looks quite easy , can you upload vi pls so i can try it...thx

0 Kudos
Message 5 of 14
(2,477 Views)

Thx jcarmody, giving me a way out for this.

0 Kudos
Message 6 of 14
(2,475 Views)

His is a VI snippet.  Just drag the image from your browser into a block diagram.

0 Kudos
Message 7 of 14
(2,473 Views)

@smercurio_fc wrote:

Why the arrays? Embrace Boolean logic! Smiley Wink


That's what I first thought, but it only works one way.

 

Example_VI.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 8 of 14
(2,468 Views)

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 Smiley Wink)

 

 

 

Download All
Message 9 of 14
(2,463 Views)

Follow-up:

 

You can eliminate the 0x00E0 constant by wiring the second input of the top OR to a NOT:

 

0 Kudos
Message 10 of 14
(2,454 Views)