Microsoft KB Archive/51495

= Using the ICHAR and CHAR Intrinsic Functions =

Article ID: 51495

Article Last Modified on 12/1/2003

-

APPLIES TO


 * Microsoft FORTRAN Compiler 4.1
 * Microsoft FORTRAN Compiler 5.0
 * Microsoft FORTRAN Compiler 5.1
 * Microsoft FORTRAN PowerStation 1.0 Standard Edition
 * Microsoft Fortran PowerStation 1.0a for MS-DOS
 * Microsoft FORTRAN PowerStation 32
 * Microsoft FORTRAN PowerStation 32
 * Microsoft FORTRAN Compiler 4.1
 * Microsoft FORTRAN Compiler 5.0
 * Microsoft FORTRAN Compiler 5.1

-



This article was previously published under Q51495



SUMMARY
The ICHAR intrinsic function converts one character to its integer ASCII value. The CHAR intrinsic function converts an integer to its corresponding ASCII character value. Both the ICHAR and CHAR functions use decimal integer values and the Extended ASCII Character Set.

The ICHAR function does not directly convert a number stored as a character array to its integer representation.



MORE INFORMATION
The integer value in each case must be between 0 and 255. The functions use modulo arithmetic to convert a number larger than 255 to a value between 0 and 255, for example, 256 &quot;wraps around&quot; to 0, 511 to 255, and so on.

The character string in each case must be a single character CHARACTER*1. If the character string is longer than one, the ICHAR function converts only the first character of the value.

The following code example demonstrates using the CHAR and ICHAR functions.

Sample Code
C Compile options needed: None

PROGRAM EXAMPLE

INTEGER*2  INT1, INT2 CHARACTER*1 CHAR1, CHAR2

CHAR1 = 'A'     INT1  = ICHAR(CHAR1)

INT2 = 90 CHAR2 = CHAR(INT2)

WRITE (*, *) 'CHAR1 = ', CHAR1, ' AND INT1 = ', INT1 WRITE (*, *) 'CHAR2 = ', CHAR2, ' AND INT2 = ', INT2

END The output of program example is as follows:

CHAR1 = A AND INT1 = 65

CHAR2 = Z AND INT2 = 90

The values 65 and 90 correspond to the decimal ASCII values for &quot;A&quot; and &quot;Z&quot; respectively.

For more information on the CHAR and ICHAR intrinsic functions, see pages 240-241 of the Microsoft FORTRAN &quot;Reference&quot; manual for versions 5.0 and 5.1 or pages 323 and 325 of the Microsoft FORTRAN &quot;Language Reference&quot; manual for version 4.1 or the FORTRAN PowerStation Language Help.

Additional query words: kbinf 1.00 4.10 5.00 5.10 type conversion

Keywords: kblangfortran KB51495

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.