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,226 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,223 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.

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 3 of 3
(2,216 Views)