LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

searching binary numbers for one bit

I'm ouputting an 8 digit binary number through a DAQ to control an 8-bit port.  I want to see if any particular bits are logic high. for exmaple, if bit five is lit, I want an LED to iluminate regardless of the state of the other bits. to do this, I think I need an 'IF' type statement but I've never seen/used one before in LabVIEW. Also is there a 'don't care' variable I could use?
 
Does anyone else have a better way of doing this?
 
Many Thanks,
Tom 
0 Kudos
Message 1 of 6
(3,581 Views)

Labview has both an if/than/else as well as a case structure.  To determine if a bit is set you can do a logic/bitwise and opperation with that bit (ie to see if 00001111 third bit is set and with 00000100) if the answer is >0 then the bit is set else it is not set.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 2 of 6
(3,577 Views)
Brilliant idea ! Got it working straight away cheers. Understand it now, apart from the less than 0 bit?
0 Kudos
Message 3 of 6
(3,563 Views)
Just meant that you do a zero comparison to determine if the bit is set (this is independant of which bit you are looking for.  a =0 means not set and a greater than zero indicates that a flag is set.
Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 4 of 6
(3,551 Views)

the zero does not refer to the bit but the value of the 8 bit result of the bitwise and operation.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 5 of 6
(3,547 Views)
Tom,
I know it's been a while since you posted your question but I have an alternate idea. (I know, it's Friday night and I'm surfing LabVIEW. I ordered a life from Amazon but it hasn't arrived yet!)
 
I think you can easily do what you want using logic functions. My characterization programs often have LED monitors that show the state of digital O/I bits. To evaluate the test, I need to extract one of the digital bits which I do by shifting it to the LSB and masking all other bits. (My PXI-6551 returns a 20 bit binary coded value, one bit per channel. This is why I included a shift function in the example.) Check out the attached code and give it a try. It should be self explanatory.
Bob
Message 6 of 6
(3,448 Views)