LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you join more than 2 numbers? Such as, three U16's where there's a High, Mid, and Low?

Solved!
Go to solution

Subject says it all really. I'd like Join Numbers to be scalable, but it isn't. So, What's the easiest way to do this?

0 Kudos
Message 1 of 8
(269 Views)
Solution
Accepted by rds2112

snip.png

Message 2 of 8
(256 Views)

I was so close. Your method doesn't have the coercion dot! Thanks!

0 Kudos
Message 3 of 8
(248 Views)

@rds2112 wrote:

I was so close. Your method doesn't have the coercion dot! Thanks!


I assume you just connected your High to the top hi input. It is just coercing the value to a U32. The upper bits of that should all be zeros if you are using a U16, so it should not matter in this case. If you are in a tight loop, the coerce maybe faster.

0 Kudos
Message 4 of 8
(242 Views)

I was getting a lot of zeros where I didn't want them. Your method makes more sense for parsing while displayed in binary.

0 Kudos
Message 5 of 8
(239 Views)

@rds2112 wrote:

Subject says it all really. I'd like Join Numbers to be scalable, but it isn't. So, What's the easiest way to do this?


How should it be made scalable? there is no 24bit or 48bit integer type, for example.

 

You already got a good solution but for more complicated problems, e.g. parsing a 1D U8 array of [R,G,B,R,G,B,R,G,B] to a U32 array of [RGB, RGB, RGB] etc. is often needed.

 

An alternative is the good old typecast, of course. Becomes more practical if you want to join 8 U8 values into a U64, for example. Using a fallen Christmas tree of "join numbers" will get tedious!

 

(Just make sure to pad correctly if the input is short.)

 

altenbach_0-1739325086776.png

Also be aware of the desired byte order of the result.

Message 6 of 8
(171 Views)

@altenbach wrote:

You already got a good solution but for more complicated problems, e.g. parsing a 1D U8 array of [R,G,B,R,G,B,R,G,B] to a U32 array of [RGB, RGB, RGB] etc. is often needed.

 

An alternative is the good old typecast, of course. Becomes more practical if you want to join 8 U8 values into a U64, for example. Using a fallen Christmas tree of "join numbers" will get tedious!


I admit the Christmas Tree can look messy, but it takes arrays and for your RGB array example seems better suited than typecast.

 

snip.png

 

Message 7 of 8
(88 Views)

@mcduff wrote:
I admit the Christmas Tree can look messy, but it takes arrays and for your RGB array example seems better suited than typecast.

Ah, I never noticed that you can mix U8 and U16 when joining and there isn't even a coercion dot. 😮

(That seem like a can of worms....)

 

It would again get messy if you want to go from seven U8 to one U64, for example.

Message 8 of 8
(73 Views)