Convert CHAR to INTEGER
Convert CHAR to INTEGER
How do I convert a CHAR (from serial input) to an INTEGER?
-
- Site Admin
- Posts: 525
- Joined: Fri Dec 31, 2010 12:30 pm
- Contact:
Re: Convert CHAR to INTEGER
The built-in ORD function will typecast a CHAR to INTEGER i.e.
This gives you the corresponding numeric ASCII value for that character. Knowing this, if you want to convert a single character (e.g. '9') to the integer value (e.g. 9) you can then say:
Note that the Convert library procedure StrToInt can be used to convert strings to
integers.
Code: Select all
VAR
ch: CHAR;
i: INTEGER;
...
...
i := ORD(ch);
Code: Select all
IF ('0' <= ch) & (ch <= '9') THEN i := ORD(ch) - ORD('0') END;
integers.