LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

wierd algorithm required - intellectual exercise

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

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 1 of 20
(3,469 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 20
(3,461 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 20
(3,445 Views)

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.

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 4 of 20
(3,444 Views)

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.

 

 

convert.png

Message Edited by rpursley8 on 04-07-2010 09:53 AM
Randall Pursley
Message 5 of 20
(3,441 Views)

Simple way to do part A.

 

Message Edited by Wayne.C on 04-07-2010 09:58 AM
Message 6 of 20
(3,431 Views)

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.)

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
Message 7 of 20
(3,412 Views)

Kudos to you!

  1. for asking a relevant question
  2. appreciating the answers received
  3. knowing when it's time to ask others for help

Shane

 

 

0 Kudos
Message 8 of 20
(3,397 Views)

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.

0 Kudos
Message 9 of 20
(3,392 Views)

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.

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 10 of 20
(3,386 Views)