Example Code

Determines Bit Values of a Numeric Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This VI determines Bit Values of a Numeric

 

Description

Usually, as a LabVIEW developers, when we need access to an individual bit of a numeric, we will use the Number to Boolean Array VI. Then, using the Index Array VI, we will pull out the bit of interest, as implemented in Single Bit Value from Numeric (using Index Array) VI. See also the block diagram in Additional Information or References.  

However, this technique may not always be convenient or desired. When programming with LabVIEW FPGA, we are very concerned about utilizing the least amount of resources. In this case, it would be beneficial to have an alternative to the Index Array for finding the value of a bit of interest of a numeric. If only one bit is desired, the code is straight-forward, using the Bit-wise AND from the Boolean palette. Such implementation is as done in Single Bit Value from Numeric LV2012 NI Verified. See also the block diagram in Additional Information or References.  

If the code requires the value of all of the bits to be found, one may want to use All Bit Values from Numeric LV2012 NI Verified. The Bit Accurate Data Size Property Node is used to programmatically handle different data types of the Input Numeric (U32) Control.

  

Requirements

LabVIEW 2012 or compatible

  

Steps to Implement or Execute Code

  1. Enter the Input Numeric
  2. Enter the Bit of Interest (zero indexed) – For Singe Bit Value VI’s
  3. Run the VI

Additional Information or References

Single Bit Value from Numeric (using Index Array) VI Block DiagramSingle Bit Value from Numeric (using Index Array)  LV2012 NI Verified BD.jpg

Single Bit Value from Numeric LV2012 NI Verified VI Block DiagramSingle Bit Value from Numeric LV2012 NI Verified BD.jpg

All Bit Values from Numeric LV2012 NI Verified VI Block DiagramAll Bit Values from Numeric LV2012 NI Verified BD.jpg

 Also-

Wikipedia: Bitwise operation

 

**This document has been updated to meet the current required format for the NI Code Exchange. **

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
altenbach
Knight of NI Knight of NI
Knight of NI
on

I don't understand the point of the code in figure 3. What makes it better than the plain, existing "number to boolean array"?

wirebirdlabs
Member
Member
on

To second Christian's concern, if #3 is better than the Number to Bool Array, why is Num to Bool Array not just an inlined wrapper of #3? If that code is truly better, perhaps the prim owner (or compiler) needs some optimization tasks in their strategic plan.