LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

byte array to string

The values are there, but recall that any C string is automatically terminated by a NULL character somewhere in the array. So, in the example above, if the number passed in to the function is less than 256, then 'high' will be 0, which when assigned as the first element of the array will cause the string to be truncated to an empty string.

 

Luis

0 Kudos
Message 11 of 13
(1,361 Views)
Yep that's what's happening.  When I convert the array back to intsthey are all zero. 
0 Kudos
Message 12 of 13
(1,357 Views)

Sorry, I replied without completely understanding the matter.  :mansad:

 

From the posts, I doubt aml1138 does the null termination correctly.

Assume you have an array str[50].

If you put 10 characters into the array, for instance, you should set str[10] = 0, since you filled upto 9th index.

To be able to "visualize" your string, the bytes in the array must correspond to printable ASCII characters, as Mert noted.

Again, as noted, there is no conversion going on here. Just single item array manipulation. 

 

If you want to get the string representation of the hex number, that's a different matter.

For example to display the hex number 0x1000 as a string (like in a message popup or file) you need:

 

Fmt (str, "0x%x[w4p0]", 4096); // [w4p0] means pad zeros to make the width of the string equal to 4

MessagePopup ("Hex", str);

 

The result is in the attachment.

Hope this helps. 

 

S. Eren BALCI
IMESTEK
0 Kudos
Message 13 of 13
(1,337 Views)