FORTRAN 77 Language Reference

Example

A program using DECODE/ENCODE:


       CHARACTER S*6 / '987654' /, T*6 
       INTEGER V(3)*4 
       DECODE( 6, '(3I2)', S ) V 
       WRITE( *, '(3I3)') V 
       ENCODE( 6, '(3I2)', T ) V(3), V(2), V(1) 
       PRINT *, T 
       END

The above program has this output:


98 76 54 
547698

The DECODE reads the characters of S as 3 integers, and stores them into V(1), V(2), and V(3).

The ENCODE statement writes the values V(3), V(2), and V(1) into T as characters; T then contains '547698'.