25.06.2013 Views

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

272 Unità di Programma<br />

Come esempio di applicazione della funzione ”di scorrimento” ISHFT, si guardi il seguente<br />

programma:<br />

PROGRAM prova_bit<br />

IMPLICIT NONE<br />

INTEGER :: n=84, m<br />

CHARACTER(LEN=29) :: formato1=’(1X,A31,I3,1X,A3,1X,B12.12)’<br />

CHARACTER(LEN=47) :: formato2=’(1X,A9,1X,I3,1X,A31,1X,B12.12, &<br />

/,1X,A33,1X,I3)’<br />

CHARACTER(LEN=47) :: formato3=’(1X,A9,1X,I3,1X,A29,1X,B12.12, &<br />

/,1X,A33,1X,I3)’<br />

! Start<br />

WRITE(*,formato1) "La rappresentazione binaria di ",n,"e’: ", n<br />

WRITE(*,formato1) "La rappresentazione binaria di ",n/2,"e’:",n/2<br />

WRITE(*,formato1) "La rappresentazione binaria di ",n/4,"e’:",n/4<br />

WRITE(*,*)<br />

m=ISHFT(n,1)<br />

WRITE(*,formato2) "Shiftando",n,"a sinistra di 1 bit si ottiene:",m, &<br />

"che corrisponde al numero intero:",m<br />

m=ISHFT(n,2)<br />

WRITE(*,formato2) "Shiftando",n,"a sinistra di 2 bit si ottiene:",m, &<br />

"che corrisponde al numero intero:",m<br />

WRITE(*,’(/,1X,A,/)’) "Viceversa:"<br />

m=ISHFT(n,-1)<br />

WRITE(*,formato3) "Shiftando",n,"a destra di 1 bit si ottiene:",m, &<br />

"che corrisponde al numero intero:",m<br />

m=ISHFT(n,-2)<br />

WRITE(*,formato3) "Shiftando",n,"a destra di 2 bit si ottiene:",m, &<br />

"che corrisponde al numero intero:",m<br />

STOP<br />

END PROGRAM prova_bit<br />

il cui output è:<br />

La rappresentazione binaria di 84 e’: 000001010100<br />

La rappresentazione binaria di 42 e’: 000000101010<br />

La rappresentazione binaria di 21 e’: 000000010101<br />

Shiftando 84 a sinistra di 1 bit si ottiene: 000010101000<br />

che corrisponde al numero intero: 168<br />

Shiftando 84 a sinistra di 2 bit si ottiene: 000101010000<br />

che corrisponde al numero intero: 336<br />

Viceversa:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!