String_TO_ArrayOfByte: Output Array and ASCII Value of the Input String
String_TO_ArrayOfByte Function
This figure shows the pin diagram of the String_TO_ArrayOfByte function:
The String_TO_ArrayOfByte function is an output Array [255] of bytes is the ASCII value of the input String.
If the Order input is TRUE, then the order of the output values corresponds to the order of the string characters at the input. This means there is a 1:1 correspondence between the order of inputs and the order of ASCII value returned at the output as explained in example 1.
If the Order input is False, then the output is such that the ASCII value of string character at input[1] of input array[1..255] is displayed in position 2 of the output. The ASCII value of string character at input[2] of input array[1..255] is displayed in position 1 of the output. Similarly the ASCII value of string character at input[3] of input array[1..255] is displayed in position 4 of the output and the ASCII value of string character at input[4] of input array[1..255] is displayed in position 3 of the output as explained in example 2.
If the Order input is TRUE then only output array is displayed in the order of string input as shown:
i_sIput='ABCDE'
i_xOrdr= TRUE
Then the string to array of byte output is:
ooutput [1] = 65
ooutput [2] = 66
ooutput [3] = 67
ooutput [4] = 68
ooutput [5] = 69
ooutput [6] = 0
As shown in the above example, Input [1] = A, its corresponding ASCII code is 65, displayed in output [1] position.
Similarly input [2] = B, its corresponding ASCII code is 66, displayed in output [2] position and so on.
i_sIput='ABCDE'
i_xOrdr= FALSE
Then the string to array of byte output is:
ooutput [1] = 66
ooutput [2] = 65
ooutput [3] = 68
ooutput [4] = 67
ooutput [6] = 0
ooutput [5] = 69
As shown in the above example,
Input [1] = A, its corresponding ASCII code is 65, displayed in output [2] position.
Input[2] = B, and its corresponding ASCII code is 66, displayed in output [1] position.
Similarly input [3] = C, its corresponding ASCII code is 67, displayed in output [4] position.
Input [4] = D, its corresponding ASCII code is 68, displayed in output [3] position.
Similarly Input [5] = E, its corresponding ASCII code is 69, displayed in output [6] position.
Input [6] = (space), its corresponding ASCII code is “ “ (that is one blank space character) is displayed in output [5] position.
NOTE: However if the number of bytes at the input is 255, Order input is FALSE. Then the last ASCII value remains in the same position (refer example 3 below).
Input:
oi_sIput [1...250]='A'
oi_sIput [251...255]='BCDEF'
Order: FALSE
Output
oOutput [1...250]:='65'
oOutput [251...255]='CBEDF'
This table describes the input pins of the String_TO_ArrayOfByte function:
Input |
Data Type |
Description |
---|---|---|
i_sIput |
STRING [1...255] |
Input string value (1...255) |
i_xOrdr |
BOOL |
TRUE: Output in order of input FALSE: Output swaps higher and lower byte. |
NOTE: It is mandatory for the user to define the size of the string input[255], else the size is taken as 80 by default.
This table describes the output pins of the String_TO_ArrayOfByte function:
Output |
Data Type |
Description |
---|---|---|
String_TO_Array OfByte |
ARRAY [0...255] OF BYTE |
Array of ASCII values Range: 0...255 |
Instantiation and Usage Example
This figure shows an instance of the the String_TO_ArrayOfByte function:
i_sIput [255]:
oInput [1] = A
oInput [2] = B
oInput [3] = C
oInput [4] = D
oInput [5] = E
i_xOrdr: TRUE
The String_TO_ArrayOfByte displays '65, 66, 67, 68, 69'
i_sIput [255]:
oInput [1] = A
oInput [2] = B
oInput [3] = C
oInput [4] = D
oInput [5] = E
i_xOrdr: FALSE
The String_TO_ArrayOfByte displays '66, 65, 68, 67, 69'