LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bit Manipulation in LV Realtime

There don't appear to be any bit manipulation functions in LV.  I just need some pretty simple tasks such as setting/clearing a particular bit in an integer.  Although these functions are available in Mathscript, apparently Mathscript won't run on a realtime target.  I've written my own function to perform this but it takes a lot more code than I would like to see (not that a LV function would necessarily be less code). 
 
Suggestions/algorithms appreciated.
 
 
0 Kudos
Message 1 of 3
(2,568 Views)
Just use the AND function (from the boolean palette) to clear a bit (set all bits to 1 except the one you want to clear).
To set a bit, use the OR function with all zeros except the bit you want to set.
For example, if your data type is U8 and you want to set bit 5, wire the U8 and a 00001000 constant (U8 in binary notation) to an OR function.

Hope this helps,
Daniel

Message Edited by dan_u on 03-21-2007 07:21 PM

0 Kudos
Message 2 of 3
(2,565 Views)

And just for future reference, there are also operations available to shift or rotate the bits of an integer.  Search for function palette for "shift" and "rotate" keywords...

-Kevin P.

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 3 of 3
(2,558 Views)