LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Initialize string of a known length

Solved!
Go to solution

 

 


@akeister wrote:

 

1. There's a coercion dot on the "Number to Hexadecimal String" function. It expects I32's, it seems. I suppose this coercion dot is justified, since it'll only happen once, but it would still be nice if there wasn't one, since it'll be converting an entire array to I32's. 


There is no coercion, that dot is meaningless and probably a bug, IMHO.

 

 


akeister wrote:

altenbach,

 

It actually works just fine without wiring anything to the "width" input. 


Only if all characters have an ASCII code larger than x09. Maybe you can guarantee that in your specific application, but it's not clean code to leave it out.

 

As an example, imagine the following two string (in hex)

 

A: 0102 0304 0506 0708

B: 1234 5678

 

WIthout the lenght wired, both would give the same result "12345678". Only if you set the lenght=2, the result will be correct and unique for both strings.

 

 

 

Message 11 of 18
(1,188 Views)

altenbach,

 

Ah, I see. Thanks!

Adrian C. Keister, Ph.D.

Certified LabVIEW Architect
Certified Professional Instructor

B.S. in Applied Physics/Computer Hardware and Software Systems, Mathematics, 2001, Grove City College.
M.S. in Mathematical Physics, 2004, Virginia Polytechnic Institute and State University.
Ph.D. in Mathematical Physics, 2007, Virginia Polytechnic Institute and State University.
0 Kudos
Message 12 of 18
(1,185 Views)

So, here's my scratch VI that converts from original string to ASCII hex codes and back. If anyone has any comments/suggestions for improvement, I'd greatly appreciate it. The two functions used in the For loop are the String Subset function, followed by the Hexadecimal String to Number function. The code appears to work fine.

 

String to ASCII Hex Codes and Back.png

 

Thanks!

 

 

Adrian C. Keister, Ph.D.

Certified LabVIEW Architect
Certified Professional Instructor

B.S. in Applied Physics/Computer Hardware and Software Systems, Mathematics, 2001, Grove City College.
M.S. in Mathematical Physics, 2004, Virginia Polytechnic Institute and State University.
Ph.D. in Mathematical Physics, 2007, Virginia Polytechnic Institute and State University.
0 Kudos
Message 13 of 18
(1,176 Views)

It looks pretty decent. You don't need to wire the size of the array to the N parameter on the loop. With auto-indexing the loop will automatically iterate over the entire array.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 14 of 18
(1,174 Views)

 


@akeister wrote:

So, here's my scratch VI that converts from original string to ASCII hex codes and back.


Looks a it complicated. try this instead:

 

 

 

Of course the back conversion should be done using a lookup table for even less code and more efficiency. 😄

Message 15 of 18
(1,167 Views)

Nice! So the first type-cast divides the string into groups of two characters each, and then you re-cast into U8's and finally get back to the original string. 

Adrian C. Keister, Ph.D.

Certified LabVIEW Architect
Certified Professional Instructor

B.S. in Applied Physics/Computer Hardware and Software Systems, Mathematics, 2001, Grove City College.
M.S. in Mathematical Physics, 2004, Virginia Polytechnic Institute and State University.
Ph.D. in Mathematical Physics, 2007, Virginia Polytechnic Institute and State University.
0 Kudos
Message 16 of 18
(1,158 Views)

I have found that concatenating an array of strings results in the same performance increase as working on a pre-allocated string of a fixed length with the added benefit of much clearer code.

 

This is the best I have managed (Average iteration time of 0.00015s on my laptop for processing 10000 elements, the OP's version takes 0.12s on my laptop)

 

Niatross_0-1712564735721.png

 

 

0 Kudos
Message 17 of 18
(177 Views)

@Worle wrote:

I have found that concatenating an array of strings results in the same performance increase as working on a pre-allocated string of a fixed length with the added benefit of much clearer code.

 

This is the best I have managed (Average iteration time of 0.00015s on my laptop for processing 10000 elements, the OP's version takes 0.12s on my laptop)


Yes, since a number of versions the memory management or specifically For-loops is quite optimized.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 18 of 18
(161 Views)