LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

U8-Byte to string function?

Does anyone know if there's a byte to string function? I have a single byte I need to convert from a U8 byte array to an acsii string char. Does this exist?

0 Kudos
Message 1 of 9
(15,267 Views)

@QRP wrote:

Does anyone know if there's a byte to string function? I have a single byte I need to convert from a U8 byte array to an acsii string char. Does this exist?


You are kind of mixing and matching what you say vs. what you want. You have a couple options. If you have a byte array you want to make a string, there is a byte array to string function. If you want the ascii character associated with a single u8 value, you can also use a type cast. It all depends what you are trying to get, but I think what you are getting at is that you need the byte array to string, which yes, there is a funciton for that.

0 Kudos
Message 2 of 9
(15,261 Views)

There is a "Byte Array To String" function.

 

If you take your single byte and 'build' it into an array of length=1, then you can convert it to an ASCII character.

0 Kudos
Message 3 of 9
(15,258 Views)

@LandBelenky wrote:

There is a "Byte Array To String" function.

 

If you take your single byte and 'build' it into an array of length=1, then you can convert it to an ASCII character.


In this case, type cast is a better option so there is no array building involved. It just takes the bit pattern in memory and interprets it as a string instead of a numeric.

0 Kudos
Message 4 of 9
(15,254 Views)

The typecast function is really all you need. Leave the central connector unwired and it will convert your U8 array of your U8 scalar to a string.

 

 

0 Kudos
Message 5 of 9
(15,245 Views)

Maybe you know, Altenbach, but does the byte array to string just do a type cast in the background? If so, is there any additional purpose to this function considering you can get the same functionality just as easily with a type cast?

0 Kudos
Message 6 of 9
(15,238 Views)

It's worth noting that Typecast is sensitive to the data type fed to it.

 

If you send it "65" as a byte, you get "A."  But if you send it "65" as a single, you get "B,". (or B\82\00\00, in slash code.)

 

Other data types yield different results.

 

If you use the Byte Array to String, you can use any data type and still get the same answer.

 

 

0 Kudos
Message 7 of 9
(15,237 Views)

@LandBelenky wrote:

It's worth noting that Typecast is sensitive to the data type fed to it.


I did not suggest to use other datatypes except U8. Of course typecast will fully adapt to the unput datatype, and the's the beauty of it. 😄


@LandBelenky wrote:

If you use the Byte Array to String, you can use any data type and still get the same answer.


Only if the values in "that other data type" fit within the range of U8. In all other cases you'll probably get garbage too. Just because "byte array to string" coerces the input to U8 does not make it any safer to the programmer who is ingnorant ofdoes not watch out for representations.


@for(imstuck) wrote:

Maybe you know, Altenbach, but does the byte array to string just do a type cast in the background? If so, is there any additional purpose to this function considering you can get the same functionality just as easily with a type cast?


 I assume that the compiler generates the same code for both functions, but I don't know for sure. I guess "byte array to string" and "string to byte array" are common enough to deserve their own function in the palette, just to make it easier for the new programmer. (Using typecast for "String to byte array" requires a type diagram constant, so is a bit more bulky.)

 

Having both "byte array to string" and "string to byte array" keeps the universe in balance.

 

Note that LabVIEW does not always have nicely matched forward/inverse pairs of functions. Some examples:

 


 


 

 

0 Kudos
Message 8 of 9
(15,215 Views)

@for(imstuck) wrote:

Maybe you know, Altenbach, but does the byte array to string just do a type cast in the background? If so, is there any additional purpose to this function considering you can get the same functionality just as easily with a type cast?


These functions are NOT identical!  There's an important difference: Byte Array to String operates in-place whereas Type Cast always creates a copy.

Message 9 of 9
(15,206 Views)