1. Convert a string to a single word integer S_I

1. Convert a string to a single word integer S_I

1.1. Instruction Description

Convert the input string starting from the address (IN) into a double word register (OUT) by taking the substring starting from the (IDX) th byte.

The format of the string must be [0 or any number of spaces] [+or \ -&# 93; [digits 0 \ -9].

The INDX value is usually set to 1, and the conversion starts from the first character of the string. The INDX value can be set to other values to start the conversion at different points in the string. This method can be used when the input string contains text that is not part of the number to be converted. For example, if the input string is "Temperature: 77", INDX can be set to 13 to skip the word "Temperature:" at the beginning of the string.

When reaching the end of the string or encountering the first invalid character, the conversion will terminate. Invalid characters are non numeric (0-9) characters or one of the following characters: plus sign (+), minus sign (-), comma (,), or period (.).

When the integer value generated by the conversion is too large for the output value, a set overflow error (M8169) will occur. For example, when the value generated by the input string is greater than 32767 or less than -32768, the instruction to convert the substring to an integer will set an overflow error.

When the input string does not contain valid values and cannot be converted, it will also set overflow error (M8169). For example, if the input string contains "A123", the conversion instruction will set M8169 (overflow) and the output value will remain unchanged.

1.2. Examples of valid and invalid input strings

Examples of valid and invalid input strings

图1 Examples of valid and invalid input strings

1.3. Attention

a) The encoding of the string is ASCII (ISO/IEC 646), please do not use other encoding methods such as UTF-8, Unicode, etc.

1.4. The valid operands of the instruction

Input/Output Data Type operand Description
IN 16 bit integer D/CV/TV/AI/AO/K/H/V/Z/FD, bit composite word (X/Y/M/C/T/S), local variable (LW) Input
IDX 16 bit integer D/CV/TV/AI/AO/K/H/V/Z/FD, bit composite word (X/Y/M/C/T/S), local variable (LW) ID
OUT 16 bit integer D/CV/TV/AO/V/Z, bit composite word (Y/M/C/T/S), local variable (LW) output

1.5. Example

Command table

NETWORK 000

LDP X000//String operations are time-consuming, so try to use edge conditions to trigger them.

Convert strings starting with D0 to double integers D100。

SI

图2 SI