- Community Home
- :
- Discussion Forums
- :
- Most Active Software Boards
- :
- LabVIEW
- :
- Concatenate 2 numbers of a 1darray

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

02-19-2019 07:26 AM

Options

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Labels:

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

Solved! Go to Solution.

02-19-2019 07:28 AM - edited 02-19-2019 07:29 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.

02-19-2019 07:31 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

02-19-2019 07:34 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel .............. Great paleotechnics YouTubeChannel... talk about stone knives and bears skins! Check it out!

02-19-2019 08:07 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

Solution

Accepted by topic author J_Print

02-19-2019 06:29 AM

02-19-2019 08:23 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.

02-19-2019 08:33 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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:

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

Regards, Jens

Kudos are welcome...

02-19-2019 08:38 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@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

03-01-2019 07:00 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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!

Cheers

Jay

Solution

Accepted by topic author J_Print

03-01-2019 05:53 AM

03-01-2019 07:18 AM - edited 03-01-2019 07:23 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@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!

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)