LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ASCII characters to HEX array manipulation

Hello,

 

Question 1: I have a file of ascii characters and I would like to convert them to a HEX array, and specify the exact index [row,column] where to insert this elements. I can currently convert into HEX but the elements get inserted one after the other and I am not specifying the location.

 

Question 2: This full contains "NULL" characters which appear as a "space" and get converted to the wrong ascii character. Should I just put an if statement: "if character is space make it equal to 0"?

 

Thank you.

 

0 Kudos
Message 1 of 12
(4,790 Views)

Hi algo,

 

this should do basically the same as your Vi does:

check.png

Why do you need to get subsets of single chars from your string?

Why do you use this shift register?

Why concatenate 1D arrays countaining just one element?

Why create a 2D array of bytes (U8) when your data source is a single string?

 

specify the exact index [row,column] where to insert this elements.

Please define row/column for a 1D array - your string is just a 1D array of bytes!

 

This full contains "NULL" characters which appear as a "space" and get converted to the wrong ascii character.

I don't think so. Please provide some proof!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 12
(4,774 Views)

How are you planning on dictating the index for the hex value as you convert?

for question 2, a simple if " ", then " "=0x00 would probably be the simplest conversion, yes.

Jon D
Certified LabVIEW Developer.
Message 3 of 12
(4,771 Views)

You can insert elements into array to specified indices using Insert into Array Function: https://zone.ni.com/reference/en-XX/help/371361J-01/glang/insert_into_array/

-Remember that only an initialized array can be used for inserting into array with specified array size: https://zone.ni.com/reference/en-XX/help/371361J-01/glang/initialize_array/

-To your second question if you don't want to consider NULL yes you can keep condition to filter them.

Thanks
uday
Message 4 of 12
(4,770 Views)

This 1D string array is just a serial output of a 2D matrix from an FPGA. So I need to put it back into 2D form in Labview.

Ex: character[0] is [0,0]; character[0] is [0,46] etc.

Would it be easy to take those values from one 2D array and then put them into another 2D array, or go directly from the string to the indexed 2D array?

 

Thank you for the quick reply

0 Kudos
Message 5 of 12
(4,761 Views)

Perhaps something like this?

 

HexConvert.png

Jon D
Certified LabVIEW Developer.
0 Kudos
Message 6 of 12
(4,756 Views)

-Edit in my previous post: Instead of insert into array use Replace Array subset.

-The below code shows an array 5x5 each with element 1.

-Then replacing the element in 1x3 with element 0.

Array_Replace_Element.png

Thanks
uday
0 Kudos
Message 7 of 12
(4,749 Views)

Hi algo,

 

Ex: character[0] is [0,0]; character[0] is [0,46] etc.

Please explain this example! Why is char[0] equal to [0, 0], but then equal to [0, 46]?

 

When you know the size of the "matrix" you can convert your 1D array easily to a 2D array using ReshapeArray…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 12
(4,741 Views)

If the size of the matrix is known from the start, and data is given for each value in the matrix (ie, if the string is 123456789, and the resulting matrix would be [[1,2,3],[4,5,6],[7,8,9]], and not something like [[1,2,3,],[4,5,6,7],[8,,9,]]) then using GerdW's suggestion, then adding a reshape array to the 2D result might be helpful.  (Then do a traverse to remove 0x20 from the array)

Jon D
Certified LabVIEW Developer.
0 Kudos
Message 9 of 12
(4,738 Views)

Sorry! Character[0] is [0,0] and then Character[1] is [0,46] my bad.

0 Kudos
Message 10 of 12
(4,735 Views)