LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to combine even and odd index of an array

Hi,

 

I have an array (u8). Let's the array is as below. Array size is always even

 

214

115

234

117

111

123

 

I would like to combine every even index value with the next odd index value and make 16bit array . odds are high bits and evens are low bits. Could you please let me how can I do it in LabVIEW?

 

115-214  or binary  0111001111010110

117-234

123-111

0 Kudos
Message 1 of 8
(2,989 Views)

Hi tintin,

 

typecast your U8 array to an U16 array. SwapBytes if needed:

check.png

Or use DecimateArray with Join…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(2,983 Views)

Decimate 1D Array followed by Join Numbers

 

You can also just use Type Cast to a U16.  At least on my system, you will have to use Swap Bytes after it to get the order you want.


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
Message 3 of 8
(2,978 Views)

Hi Team,

I have recently faced issue related to typecasting from U8 to U16 and it works fine for even numbers but for the odd numbers the typecast function ignores the last U8 byte, Is it a bug?

 

I have used other ways to achieve the solution but typecast should consider the last odd byte as well.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 4 of 8
(111 Views)

@PalanivelThiruvenkadam wrote:

Hi Team,

I have recently faced issue related to typecasting from U8 to U16 and it works fine for even numbers but for the odd numbers the typecast function ignores the last U8 byte, Is it a bug?

 

I have used other ways to achieve the solution but typecast should consider the last odd byte as well.


Type cast works for me, but Decimate requires an even number.

Yamaeda_0-1714036423433.png

 

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 8
(85 Views)

Hi Yamaeda,

 


@Yamaeda wrote:
Type cast works for me, but Decimate requires an even number.

Only when you typecast into a scalar U16: what happens when typecasting to an array of U16?

 

Like this:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 8
(78 Views)

The problem is when you wanted to typecast to array of U16 from array of U8 it ignores the last odd byte which means it executes as same as decimate array function

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 8
(64 Views)

@GerdW wrote:

Hi Yamaeda,

 


@Yamaeda wrote:
Type cast works for me, but Decimate requires an even number.

Only when you typecast into a scalar U16: what happens when typecasting to an array of U16?


To be fair, that post didn't specify that. 🙂 

Yes, my LV2019 reacts as your example.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 8
(52 Views)