LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Masking binary bits to extract wanted information

Solved!
Go to solution

Hey guys,

 

Still relatively new to labview but have run into a problem which I am pretty sure is a simple one. Ive got a VI here which takes two inputs from two enums (one containing the information X,Y and Z and the other containing A+B and A-B)

 

I want to mask off the bits coming out of the compound arithmetic and extract the axis and operation (represented as 0,1 or 2)

 

So if I choose Y and A-B, the axis will show 1 and 1

If i chose X and A+B the axis will show 0 and 0

If i chose Z and A+B the axis will show 2 and 0

 

if that makes sense. I know its something simple but I cant see it - Any help would be greatly appreciated.

 

Thanks!

0 Kudos
Message 1 of 6
(3,415 Views)
Solution
Accepted by topic author Muri777

I'm not certain what you are trying to do, but I believe you issue is you aren't shifting the bits back.  After the AND with 0b110000 you should logical shift back -4.

 

Why do you need to do this in the first place?  If you what to combine two pieces of information into a single type, use the Bundle, or Bundle by Name making it into a cluster that can be more easily passed around and unbundled.

 

Oh and your Enums Axis and Operation can have their representation changed to a U8 so you don't need the conversion.  Right click the control and go to Representation >> U8

0 Kudos
Message 2 of 6
(3,402 Views)

Yep, just got this now haha. I shifted it back by -4 and the operation works as 0 1 or 2 (yay!) but now when i typecast it back to its original ENUM style, it only comes up as X or Z. (as in 0 = X, 1 = Z, 2  = Z) which is really confusing. Would anyone happen to know why this is?

 

Thanks!

 

Muri.

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

You really should type def your enums.  That could be part of your problem.

 

You also do not need to use the AND for the axis representation.  The logic shift will remove the lower bits for you.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 6
(3,365 Views)

Thanks for your help guys!

 

Changing the axis to a type-def does not solve my problem unfortunately. Must just be a little bug or something? Ill get some colleagues to check over my code to see that I havent missed anything - Unless you guys can see something?

 

Thanks again!

0 Kudos
Message 5 of 6
(3,357 Views)

Just figured it out guys - since the value coming out of the and gate was an 8 bit and the input into the typecast is 16 bit, there was some weird conversion problem and the program seemed to forget the middle bit. Can be fixed by either changing the axis representation or by adding a U16 converter after the AND gate.

 

Thanks all for the help!!

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