Extended instructions
9.2 String and character
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
359
ATH and HTA (Convert to/from ASCII string and hexadecimal number) instructions
Use the ATH (ASCII to hexadecimal) and HTA (hexadecimal to ASCII) instructions for
conversions between ASCII character bytes (characters 0 to 9 and uppercase A to F only)
and the corresponding 4-bit hexadecimal nibbles.
Table 9- 40 ATH instruction
in:=_variant_in_,
n:=_int_in_,
out=>_variant_out_);
Converts ASCII characters into packed hexadecimal digits.
Table 9- 41 Data types for the ATH instruction
Pointer to ASCII character byte array
Number of ASCII character bytes to convert
Pointer to the converted hexadecimal byte array
Conversion begins at the location specified by parameter IN and continues for N bytes. The
result is placed at the location specified by OUT. Only valid ASCII characters 0 to 9, lower
case a to f, and uppercase A to F can be converted. Any other character will be converted to
zero.
8-bit ASCII coded characters are converted to 4-bit hexadecimal nibbles. Two ASCII
characters can converted into a single byte containing two 4-bit hexadecimal nibbles.
The IN and OUT parameters specify byte arrays and not hexadecimal String data. ASCII
characters are converted and placed in the hexadecimal output in the same order as they
are read. If there are an odd number of ASCII characters, then zeros are put in the right-
most nibble of the last converted hexadecimal digit.
Table 9- 42 Examples: ASCII-to-hexadecimal (ATH) conversion