LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert Integer to ASCII with only necessary components?

Solved!
Go to solution

So the issue I am having is that I convert an integer to string using type cast. It gives me the string in ASCII, but unfortunately the type cast function maintains unused integer space resulting in extra characters in my string. I tried changing the integer representation to byte but I quickly realized that I would not be able to have multiple characters. I need a way to remove the extra characters, but if the integer is high enough make another. The situation is like this byte array:

 

 0 0 0 24 0 6 127 254

 

Think of it as a base 256 counting system that I want to convert it to. I don't want all those leading zeros just like I wouldn't want e.g. 00000433 in base 10, but I want to have the ability to go to e.g. 1433 when the integer is high enough.

 

Pictures of my block diagram and front panel results are attached.

Download All
0 Kudos
Message 1 of 6
(4,527 Views)

Use the string function "Search and Replace String" to replace the nulls with empty strings.  Be sure to wire a True to the "replace all" input.

Message 2 of 6
(4,505 Views)

@paul_a_cardinale wrote:

Use the string function "Search and Replace String" to replace the nulls with empty strings.  Be sure to wire a True to the "replace all" input.


THis will not work since it will remove ALL NULL bytes and NULLs are valid if surrounded by valid numbers. He only wants to remove leading NULLs. I would search the resulting string for the first non-NULL character and split the string at that point.



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
Message 3 of 6
(4,501 Views)
Solution
Accepted by topic author String_Theory

I'll neglect negative values for the moment.

 

TrimZerosBase256.png

 

 

Message 4 of 6
(4,496 Views)

@Mark_Yedinak wrote:

@paul_a_cardinale wrote:

Use the string function "Search and Replace String" to replace the nulls with empty strings.  Be sure to wire a True to the "replace all" input.


This will not work since it will remove ALL NULL bytes and NULLs are valid if surrounded by valid numbers. He only wants to remove leading NULLs. I would search the resulting string for the first non-NULL character and split the string at that point.


Yes, you are right Mark. Although, I don't know how to find the first character not equal to the NULLS because it may be different everytime. I did come up with a solution, but it's more complicated than I like. Oh well, can't win them all. Thank you for your support.

0 Kudos
Message 5 of 6
(4,481 Views)

@Darin.K wrote:

I'll neglect negative values for the moment.



That is fine. I think your solution is better than mine, as I have discovered mine excludes a few values. Thank you for the time you put into this.

0 Kudos
Message 6 of 6
(4,480 Views)