LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to change a specific bit to 0 or 1?

Hello,
i think i have an easy problem but i dont get the solution.
What is want to do is a vi with this parameters:
Input:
current-value (U32)
BitNumber (0..31)
State (Bool)

Output:
new-value (U32)

for example if
current-value = 00000000 00000000 00000000 00000111 (binary)
BitNumber = 2 (dez)
State = False

Then the new-value should be: 00000000 00000000 00000000 00000011 (binary)

With same parameters and State = True the new-value is unchanged because ithe bit is already true.

How do i do this?

Thanks
0 Kudos
Message 1 of 30
(5,215 Views)

Hi OnlyOne,

here is one solution for you.

Mike



Message Edited by MikeS81 on 05-06-2008 11:06 AM
Message 2 of 30
(5,202 Views)
Hi,
this is a nice problem. Hope this helps



greets, Dave

P.S. Mike, it's hard to beat you Smiley Very Happy


Message Edited by daveTW on 05-06-2008 11:12 AM
Greets, Dave
Download All
Message 3 of 30
(5,198 Views)


@daveTW wrote:

P.S. Mike, it's hard to beat you Smiley Very Happy


But i will try it with a perharps more generic solution since you can mask more bits at a time:



hope this helps,
Norbert





Message Edited by Norbert B on 05-06-2008 04:18 AM
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 4 of 30
(5,188 Views)
Hi Mike,
thank you for your fast answer.
I was always trying to solve it like Dave and didnt think about the way that you did it (which is much easier to understand).
thx
0 Kudos
Message 5 of 30
(5,186 Views)

Nice solution Norbert,

but what´s that? Smiley Happy

Mike



Message Edited by MikeS81 on 05-06-2008 11:21 AM
Message 6 of 30
(5,182 Views)
Your problem is indeed easy to solve ! Among several other solutions :






Message Edité par JB le 05-06-2008 11:24 AM
0 Kudos
Message 7 of 30
(5,176 Views)
OMG, Mike found a "nearly WEQ" in my example 😉
BUT, it is not really a WEQ (sure in this screeny), but the boolean constant is the way to determine if to switch 0=>1 or 1=>0.... I'd better document that in the future......

Norbert

EDIT: I know that this could be done by switching True-case to false and vice versa as well.... But i think (even if its currently a WEQ), it is more readable......


Message Edited by Norbert B on 05-06-2008 04:28 AM
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 8 of 30
(5,162 Views)
A few minutes to make an example and I must note that others have already posted a lot of answers and comments. You are really too fast !
0 Kudos
Message 9 of 30
(5,153 Views)
Here the reworked example as vi, maybe someone could use it......


Norbert
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 10 of 30
(5,146 Views)