LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to change a specific bit to 0 or 1?

In general, I would really recommend to stick with a solution that does not use any thick green wires (Dave's solution above is better! :)). Bit manipulations should be done with blue wires. Going the detour via boolean arrays is easily an order of magnitude slower and requires an order of magnitude more memory.
 
For some illustrations, have a look at the results of the old bit twiddling challenge: http://zone.ni.com/devzone/cda/tut/p/id/5307


Message Edited by altenbach on 05-06-2008 07:08 AM
Message 11 of 30
(3,539 Views)
Altenbach,

you are, in general, correct about the performance issues. I just made a small benchmark with my solution and dave's. dave's is about 6 times faster than mine.
But now there is one thing i am wondering:
My solution depends on the actual "length" of the number; the higher the value, the longer the vi takes for 1,000,000 iterations. The time does increase about 10% (950 ms up to about 1100). BUT: It does not have to much impact how many bits i mask.
dave's solution does only mask one bit at an iteration, so i think, if masking more bits, the time used to solve this will increase in reference to the number of bits. A single bitmask took (for 1,000,000 iterations) 170 ms on my machine. So if the increase for "bits to mask" is additive, my solution would be equal to dave's @ about 6 bits.

So, just wondering: is my thinking correct? If it is, is there a more elegant way to solve this?

Please note that the screenshots in the link to the bit twiddling challenge do not enlarge on my system... (i use firefox, but it does not work in IE either.....)

Norbert
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 12 of 30
(3,522 Views)
Hi Norbert,
this is my update...



greets, Dave


Message Edited by daveTW on 05-06-2008 05:54 PM
Greets, Dave
Download All
Message 13 of 30
(3,502 Views)


MikeS81 wrote:

Nice solution Norbert,

but what´s that? Smiley Happy

Mike



Message Edited by MikeS81 on 05-06-2008 11:21 AM


Mike,

That's Norbert's version of Rube Goldberg Code. Smiley Very Happy

- Partha ( CLD until Oct 2024 🙂 )
0 Kudos
Message 14 of 30
(3,466 Views)
Dave,

that's a very nice, "generic" solution for masking. My first approach was actually very similar, but i missed the part i encircled in blue. That's why i switch to the less performant arrayhandling, which is really not the best as altenbach correctly pointed out....



Norbert


Message Edited by Norbert B on 05-08-2008 02:23 AM
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 15 of 30
(3,395 Views)

LilySamchuk_0-1692255358493.png

Hello. I was told that it is possible also to change specific bit in this way (picture attached). But it doesn't work for me. Can someone help me please? What I want to do is to change specific bit value in the register. Thank you 

0 Kudos
Message 16 of 30
(1,101 Views)

Hi Lily,

 

you forgot to attach your code - we cannot debug/edit/run images in LabVIEW!

 


@LilySamchuk wrote:

Hello. I was told that it is possible also to change specific bit in this way (picture attached). But it doesn't work for me. Can someone help me please? What I want to do is to change specific bit value in the register. Thank you 


  • Which way of "change a bit" do you need? Clear, set, negate? Use AND, OR, XOR…
  • Why is there a coercion dot in your image?
  • Which bit do you want to change?
  • Do yo want to change a single bit or more than one bit at once?

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 17 of 30
(1,091 Views)

for example, I have a register with address xF13 and data there x1111. I want to change bit 4 from 1 to 0. How this can be done ? thank you 

0 Kudos
Message 18 of 30
(1,081 Views)

Hi Lily,

 


@LilySamchuk wrote:

for example, I have a register with address xF13 and data there x1111. I want to change bit 4 from 1 to 0. How this can be done ?


The register address is irrelevant for the task:

When clearing bits you need to create a "negative" mask, that's what the inverted input does…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 19 of 30
(1,074 Views)

Will it also work in a reverse order ? To change 0 to 1 ? 

0 Kudos
Message 20 of 30
(1,061 Views)