From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenate 2 numbers of a 1darray

Solved!
Go to solution

Hello everyone,

 

one question from a LabView noob!

 

I want to concatenate 2 numbers from an 1darray to one number.

 

For example [123,456] to [123456].

 

In my Vi this can be solved for small numbers, but it s not working when the numbers get to big. What am I doing wrong? 😄

 

Thanks for any help!

 

Cheers,

Jay

0 Kudos
Message 1 of 13
(5,470 Views)

Your datatype is a U8 which means it can only have the values between 0 and 255.

 

Try U32 instead!

 

PS:  You don't need the constants 0 and 1 wired to the indices of your Index Array function.  It will give those indices by default when unwired.

Message 2 of 13
(5,468 Views)

The biggest problem with your Picture (please, attach executable code, like a VI) is that you are trying to cram a 6-digit number (123456) into a u8, which is at most 3 (decimal) digits, e.g. 256.

 

If you had looked at the intermediate string, you might have seen "123456" and might have realized "Oops, how do I express this as a U8?".  Do you know how to force the Scan from String function to output a U32 (or an I32)?

 

Bob Schor

Message 3 of 13
(5,462 Views)

There are also function under the Numerics >>> Data Manipulation palette that are useful.

 

Join numbers

Swap Byte

Swap word

Type Cast

 

You should play with those a bit. Like Radigas said "You have to fiddle with it a bit."

 

Have fun!

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 13
(5,456 Views)

Thank you everyone for your quick response!

 

It is working when I am unsing U32 instead of U8!

 

Bob_Schor actually I don t know hot to force the funtion..how is this gonna work?

 

Another question: When I am using hexadecimal numbers it doesnt work, for example:

I have the numbers [47,31] convert them into hex[2F, 1F]  and get [127B] with the VI. 127B converted into decimal is 4731.

How can I get 2F1F, which is 12063?

 

I hope my question is clear!

 

Thanks again!

 

Jay

 

 

 

0 Kudos
Message 5 of 13
(5,427 Views)
Solution
Accepted by topic author J_Print

Convert them to hex strings.  %x.   Or you might need %2x if you want to ensure that numbers less than 16 have 2 characters.   ("0A" for 10 instead of just "A").

 

To force a datatype when converting from string to integer, wire a constant to the dot at the lower left of the Scan from String Function.  Assign it whatever datatype you want such as right clicking on it and picking Representation >> U32.

Message 6 of 13
(5,415 Views)

I have the numbers [47,31] convert them into hex[2F, 1F]  and get [127B] with the VI. 127B converted into decimal is 4731.

How can I get 2F1F, which is 12063?


For that task you can use the already mentioned "Join Numbers" primitive:

grafik.png

 

Or if you want to convert your complete array with 1 function use "Type Cast":

grafik.png

 

Regards, Jens

Kudos are welcome...
Message 7 of 13
(5,404 Views)

@J_Print wrote:

Bob_Schor actually I don t know hot to force the funtion..how is this gonna work?

 


Put down a Scan from String function.  Right-click it, choose "Help", and read the Detailed Help.  Look at the explanation for the lowest left input terminal -- it defines the Type and Default Value of the corresponding output.  So if you wire the default I32 Numeric (from the Numeric Palette), you'd get an I32 out.  What if you want an I16, or a Sgl?  Right-click the numeric you have wired, and change its Representation to whatever you want.

 

Bob Schor

Message 8 of 13
(5,400 Views)

Hello guys,

 

I still have a small problem with my evaluation.

Numbers that are less than 16 are not correctly output. I took the advice from RavensFan and replaced %x with %2x, but it still don t work.

The concatenation of the two numbers fails. The numbers for example [2F, B] are transformed into 2FB (when %x is used) and 2F B (when %2x is used). The correct form would be 2F0B.

 

Where is my mistake?

 

Thanks for any help! Smiley Happy

 

Cheers

Jay

0 Kudos
Message 9 of 13
(5,336 Views)
Solution
Accepted by topic author J_Print

@J_Print wrote:

Hello guys,

 

I still have a small problem with my evaluation.

Numbers that are less than 16 are not correctly output. I took the advice from RavensFan and replaced %x with %2x, but it still don t work.

The concatenation of the two numbers fails. The numbers for example [2F, B] are transformed into 2FB (when %x is used) and 2F B (when %2x is used). The correct form would be 2F0B.

 

Where is my mistake?

 

Thanks for any help! Smiley Happy

 

Cheers

Jay


You are over thinking the problem. Way too many conversions to get from U8 to U16. Here is a simpler way (oops! JensG69 already provided this solution)

 

bd.png

 

fp.PNG

Message 10 of 13
(5,331 Views)