LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Decoding bit values, (e.g. bit# 7 (MSB, 0=LSB) in 0xFF = 1)

I needed to "decode" or read out the bit-status of any specified bit in any given number (from U8 to U32), and as such I made a "tiny" VI to give that functionality.

Since I'm rahter fresh to this whole game, I would like to get some feedback on the code.

The VI will be used as a sub-vi in a larger project, to decode status bytes which I can then use to control indicators for various processes.

I've inlcuded just a little bit of documentation, but I have not yet made an icon as my preffered icon editor is on a different computer.

I suspect I'm not as efficient in this vi as I could have been, but I'd like some feedback whether or not I have made any big boo-boo's, say on a scale from 1 to 10 with 10 beeing perfect. 🙂

One comment I can give myself is that the U8 for bit-position is converted when passed to the for-loop... but on the other hand, it feels "wrong" to use the default data-type here, since the maximum value that makes sense to pass to the vi is 31 (for an U32 data-type).
---------------------------------------------------

Project Engineer
LabVIEW 2009
Run LabVIEW on WinXP and Vista system.
Used LabVIEW since May 2005

Certifications: CLD and CPI certified
Currently employed.
0 Kudos
Message 1 of 6
(4,065 Views)
I usually transform the data to a bit array.
Message 2 of 6
(4,060 Views)
Absolutely sweet!

Sometimes the biggest challenge with LabVIEW is to find all those pre-made functions! -I find myself "re-inventing the wheel" on several occasions, just because I did not realise that LabVIEW already had the code tucked away on some panel!

Thanks!
---------------------------------------------------

Project Engineer
LabVIEW 2009
Run LabVIEW on WinXP and Vista system.
Used LabVIEW since May 2005

Certifications: CLD and CPI certified
Currently employed.
0 Kudos
Message 3 of 6
(4,057 Views)
If you don't want to go through the expense of allocating a 32 byte boolean array, you can just use a plain masking operation. Remember that the logical operations perform bitwise on integers. (scale by power of two is very cheap for integers, because it uses a simple bit shift, same as in example 2).

Message Edited by altenbach on 12-04-2005 04:03 PM

Download All
Message 4 of 6
(4,039 Views)
okay.. this reply is very late I guess, but better late than never!

I just wanted to thank you, Altenbach, for your contribution, I will use this technique in my current VI.

Thanks!
---------------------------------------------------

Project Engineer
LabVIEW 2009
Run LabVIEW on WinXP and Vista system.
Used LabVIEW since May 2005

Certifications: CLD and CPI certified
Currently employed.
0 Kudos
Message 5 of 6
(3,941 Views)

Tight.

I can use this as well.

Thanks.

0 Kudos
Message 6 of 6
(3,773 Views)