04-07-2010 08:22 AM
Approaching LabVIEW from a Mech Eng background and not a Comp Sci or Electronics background, I feel I may be lacking a bit of the fundamental datatype knowledge and thought processes which could make my life easier here.
I have been posed a problem, I don't have to solve it yet, I may never have to solve it, but I'm attacking it anyway as an intellectual exercise in it's own right.
Enum contains values 1-11
Numbers are used as Hex strings 4 digits wide (e.g. 000A =10)
each number has now been assigned another number that corresponds to it too.
0=0001; 1= 0002; 2= 0004; 3= 0008; 4= 0010; 5= 0020; 6= 0040; 7=0080; 8=0100; 9=0200; 10=0400; 11=0800.
- Part A of the problem is to convert the Enum into the new values.
- Part B of the problem is that I can read a 4 digit Hex value, which contains the OR of 3 of the generated numbers and I need to know:
(1) If number x was included in the OR function.
(2) [extension of the exercise] which numbers were OR'd together!!
I'm getting there, but my code is clunky, so I'd be interested in any ideas anyone has on this one.
As I mentioned earlier, it is no longer necessary for the business, I'm just persuing it for my own learning
Cheers
James
04-07-2010 08:32 AM
Part A is easy.
Use the enum as an index then use Index Array to index an array with the appropriate translation from an array (constant or stored in SR if the translation can change)
For part B I would look at bit-wise compares with masks.
Ben
04-07-2010 08:47 AM
The easy solution to B is to use Number to Boolean array and check indexes for True. Those are the indexes of the OR'd numbers.
/Y
04-07-2010 08:48 AM
Ben wrote:Part A is easy.
Use the enum as an index then use Index Array to index an array with the appropriate translation from an array (constant or stored in SR if the translation can change)
For part B I would look at bit-wise compares with masks.
Ben
Quick response. I've only just finished my first attempt at Part A (file attached). - Didn't think of anything that simple Doh!!!
Part B - don't know what you are talking about. I'm Mech Eng remember - no speaky computer talky very wellie.
*** reboot from start ****
(Sorry Ben) Bit - wise. I'm just bit-dim.
04-07-2010 08:49 AM - edited 04-07-2010 08:53 AM
In Part A, the value of the Enum, n translates to a value 2^n
For Part B, take the 4-digit Hex value, use the Number to Boolean Array primitive to convert the number to a boolean array. The values of each element (LSB in position 0 of array) are TRUE when that Enum was OR'd.
 
04-07-2010 08:58 AM - edited 04-07-2010 08:58 AM
Simple way to do part A.

04-07-2010 09:12 AM
Well....
I thought it was an intellectual exercise, it seems it wasn't really that hard if you know what your computer does!!
That was an awesome array of responses and solutions to the problem - in such a short space of time too!
I love Wayne's utter simplification of my code with 1 LabVIEW function - amazing.
and Yamaeda's method of detecting which Ports have been OR'd togther is so gob-smackingly simple I'm surprised it works!!
Code snippets always good Randall - unfortunatley I'm working in 8.6 on this Laptop, so I can only see this snippet, not use it, and I couldn't work out how to make use of the binary array earlier myself (see Yamaeda's solution - you were pipped to post!)
Great.
Kudos to you all
James
(no One solution to mark as you have all had input into the solution.)
04-07-2010 09:49 AM
Kudos to you!
Shane
04-07-2010 10:06 AM
James,
Experience has a lot to do with it. In fact I'd be real curious to tally up how many years of engineering and LV experience were just combined to answer your question.
04-07-2010 10:21 AM
Wayne.C wrote:James,
Experience has a lot to do with it. In fact I'd be real curious to tally up how many years of engineering and LV experience were just combined to answer your question.
Tally up 34 years for my part.*
Ben
* Learned boolean logic in 1976.
Re: Bit-wise
The logical operators like "And" "Or" etc will operate on a bit by bit basis (bit-wise) when you pass them numerics. So if you have the number "8" which is 1000 in binary and "And" it with 15 (1111) the And will return "8" since that is the only bit that is set in both numbers. Bit-wise operation let you test indiviual or set of bits.