LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

concatenate two 8-bit integers into single 16-bit integer

I have an array of four elements as a numeric value. Lets take element 1 is 90 and element 2 is 50 and element 3 is 70 and element 4 is 60 i need an output as reverse of first two elements result should be 5090 and another one is 6070.if anyone have some suggestions let me know it will be helpful.

0 Kudos
Message 1 of 15
(1,093 Views)

You mean something like below?

 

concatenate..JPG

edit: the solution posted below by rolfk is the better solution.

0 Kudos
Message 2 of 15
(1,073 Views)

Your data stream is in the so called Little Endian format (LSB first).

 

LabVIEW has an Unflatten from String function that can do that perfectly for you. You just have to convert your Byte Array first into a String (in LabVIEW a String is simply syntactic sugar for a Byte Array).

 

Unflatten from Byte Array.png

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 15
(1,067 Views)

This one i tried already. Is there any other simplest way to achieve this.

0 Kudos
Message 4 of 15
(1,052 Views)

@Rajsakthi wrote:

This one i tried already. Is there any other simplest way to achieve this.


Define "simple". 😁

 

Unflatten from Byte Array.png

Same as above but with an extra alternative.

 

The first definitely scales much better if your data suddenly gets longer. The second is a bit more explicit if you know ahead that your input stream never will get larger.

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 15
(1,048 Views)

Haha..Can we simplify the steps in a better way.

0 Kudos
Message 6 of 15
(1,042 Views)

In this how can i add the 1d array to it....iam trying but not getting.

0 Kudos
Message 7 of 15
(1,037 Views)

Hi Raj,

 


@Rajsakthi wrote:

In this how can i add the 1d array to it....iam trying but not getting.


In Rolf's example there already is an array input called "data in".

Why do you want to "add" an array? What is the math operation good for?

 

Why don't you show your current VI to allow us to give suggestions how to improve it?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 15
(1,024 Views)

@rolfk wrote:

 

(...) The second is a bit more explicit if you know ahead that your input stream never will get larger.


 

The alternative is no good as it concatenates bit-wise, so 010011 (i.e. 50, LSB) concatenated with 0101101 (i.e. 90, LSB) to give 01011010010011 (12890, LSB).

0 Kudos
Message 9 of 15
(1,012 Views)

@Rajsakthi wrote:

In this how can i add the 1d array to it....iam trying but not getting.


Not sure what you mean. All examples feature a 1D array, either as a control (rolfk's proposed solution) or as a constant (my reply).

Do you want a solution for a 1D array of general size (i.e. not limited to four elements)? 

0 Kudos
Message 10 of 15
(1,005 Views)