La codifica binaria della informazione: differenze tra le versioni
Riga 1: | Riga 1: | ||
− | '''La codifica binaria della informazione'''''''' | + | <html> |
− | presente paragrafo si riferisce alle prime due lezioni del corso di Fondamenti | + | |
− | di Informatica e Laboratorio di Informatica. '''Parole | + | <head> |
− | chiave: '' | + | <meta http-equiv=Content-Type content="text/html; charset=windows-1252"> |
− | 754 a singola e doppia precisione. | + | <meta name=Generator content="Microsoft Word 14 (filtered)"> |
− | in queste iniziali lezioni consiste nell'illustrare in quale maniera | + | <title>Microsoft Word - La codifica binaria dell'informazione_revisione2012.doc</title> |
− | l'informazione, per adesso soltanto numerica, viene memorizzata nella memoria | + | <style> |
− | RAM (Random Access Memory) di un sistema di calcolo rispettando standard | + | <!-- |
− | condivisi, per poi essere elaborata attraverso un linguaggio di programmazione. | + | /* Font Definitions */ |
− | In particolare si tratteranno: la codifica binaria, la codifica esadecimale, le | + | @font-face |
− | conversioni di base, il concetto di errore di una codifica, la codifica di | + | {font-family:"Cambria Math"; |
− | numeri interi con e senza segno in CA2 (complemento a 2), la codifica di numeri | + | panose-1:2 4 5 3 5 4 6 3 2 4;} |
− | reali in singola e doppia precisione secondo lo standard IEEE 754, gli effetti | + | @font-face |
− | sulla dichiarazione delle variabili signed e unsigned di tipo char ed int, e | + | {font-family:Calibri; |
− | delle variabili float e double in linguaggio C. 2 La memoria di lavoro La memoria RAM (Random Access Memory) è la | + | panose-1:2 15 5 2 2 2 4 3 2 4;} |
− | memoria di lavoro (elaborazione) di un sistema di calcolo; per semplicità essa | + | @font-face |
− | può essere rappresentata come una tabella organizzata in righe, ciascuna delle | + | {font-family:"Segoe UI Symbol"; |
− | quali (per ora chiamata word) viene suddivisa in 4 colonne o blocchi, da ora in | + | panose-1:2 11 5 2 4 2 4 2 2 3;} |
− | poi chiamati byte, costituiti da una sequenza di 8 bit (binary digit) ovvero 8 | + | /* Style Definitions */ |
− | cifre che possono assumere soltanto valori 0 o 1. In generale, ogni programma di elaborazione | + | p.MsoNormal, li.MsoNormal, div.MsoNormal |
− | si occupa della gestione delle informazioni per unità elementari corrispondenti | + | {margin-top:0cm; |
− | alla dimensione dei byte, senza necessariamente scendere al livello di dettaglio | + | margin-right:0cm; |
− | dei singoli bit, per questo motivo si dice che la unità minima indirizzabile | + | margin-bottom:8.0pt; |
− | (ovvero dotata di un indirizzo in memoria corrispondente alla posizione in | + | margin-left:0cm; |
− | memoria RAM) è il singolo byte. Il modo più diffuso di numerare i byte, | + | line-height:107%; |
− | iniziando sempre dal numero progressi 0, è da destra verso a sinistra (“little | + | font-size:11.0pt; |
− | Endian”), laddove il verso dall’alto verso il basso è ovviamente relativo a | + | font-family:"Calibri","sans-serif"; |
− | come più avanti si dirà essere partizionata la intera memoria RAM. 3 Le regole per le trasformazioni di base Dato un numero, le basi del sistema di | + | color:black;} |
− | numerazione che si usano per leggere tale numero sono la base 2 (binaria), 8 | + | h1 |
− | (ottale), 16 (esadecimale); assegnata una base del sistema di numerazione, le | + | {mso-style-link:"Titolo 1 Carattere"; |
− | cifre sono date da 0 fino a numero base – 1. Dopo la cifra 9, si aggiungono A, | + | margin-top:0cm; |
− | B, C, D, E, F per formare la base di un sistema esadecimale. Assegnato un numero codificato in base 2, si | + | margin-right:0cm; |
− | decodifica facilmente in base 10; esempio della codifica chiamata “in binario | + | margin-bottom:9.35pt; |
− | puro”: (1010.101)2 = (1 x | + | margin-left:7.7pt; |
− | 0 x | + | text-indent:-.5pt; |
− | 0 x 2-2 + 1 | + | line-height:107%; |
− | per l’operazione inversa, si utilizzano due algoritmi rispettivamente per la | + | page-break-after:avoid; |
− | parte intera e decimale del numero: 3.1 Algoritmo di Horner - divisioni successive | + | font-size:12.0pt; |
− | colonna a sinistra, lo si divide per 2, riportando quoziente sotto il dividendo | + | font-family:"Times New Roman","serif"; |
− | mentre il resto accanto al dividendo, e così via fino a raggiungere il | + | color:black;} |
− | quoziente 0. La parte intera del numero in binario è la sequenza dei resti, | + | h2 |
− | presa dal basso verso l’alto. | + | {mso-style-link:"Titolo 2 Carattere"; |
− | successive | + | margin-top:0cm; |
− | colonna a sinistra, lo si moltiplica per 2, riportando: 1. | + | margin-right:0cm; |
− | Se | + | margin-bottom:10.35pt; |
− | il prodotto è | + | margin-left:.5pt; |
− | prodotto 2. | + | text-indent:-.5pt; |
− | Se | + | line-height:107%; |
− | il prodotto è | + | page-break-after:avoid; |
+ | font-size:10.0pt; | ||
+ | font-family:"Times New Roman","serif"; | ||
+ | color:black;} | ||
+ | span.Titolo2Carattere | ||
+ | {mso-style-name:"Titolo 2 Carattere"; | ||
+ | mso-style-link:"Titolo 2"; | ||
+ | font-family:"Times New Roman","serif"; | ||
+ | color:black; | ||
+ | font-weight:bold;} | ||
+ | span.Titolo1Carattere | ||
+ | {mso-style-name:"Titolo 1 Carattere"; | ||
+ | mso-style-link:"Titolo 1"; | ||
+ | font-family:"Times New Roman","serif"; | ||
+ | color:black; | ||
+ | font-weight:bold;} | ||
+ | .MsoChpDefault | ||
+ | {font-family:"Calibri","sans-serif";} | ||
+ | .MsoPapDefault | ||
+ | {margin-bottom:8.0pt; | ||
+ | line-height:107%;} | ||
+ | @page WordSection1 | ||
+ | {size:595.3pt 841.9pt; | ||
+ | margin:71.0pt 58.45pt 59.85pt 55.9pt;} | ||
+ | div.WordSection1 | ||
+ | {page:WordSection1;} | ||
+ | /* List Definitions */ | ||
+ | ol | ||
+ | {margin-bottom:0cm;} | ||
+ | ul | ||
+ | {margin-bottom:0cm;} | ||
+ | --> | ||
+ | </style> | ||
+ | |||
+ | </head> | ||
+ | |||
+ | <body lang=IT> | ||
+ | |||
+ | <div class=WordSection1> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:14.5pt; | ||
+ | margin-left:76.7pt'><b><span style='font-size:14.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>La codifica binaria della informazione</span></b><b><span | ||
+ | style='font-size:8.0pt;line-height:107%;font-family:"Arial","sans-serif"'> </span></b><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:151.25pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-.5pt;line-height:107%'><span style='font-size:10.0pt;line-height: | ||
+ | 107%;font-family:"Arial","sans-serif"'>Vitoantonio Bevilacqua </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:2.1pt; | ||
+ | margin-left:202.6pt'><span style='font-size:9.0pt;line-height:107%;font-family: | ||
+ | "Arial","sans-serif"'> </span><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:25.0pt; | ||
+ | margin-left:155.45pt'><u><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>bevilacqua@poliba.it</span></u><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'> </span><b><span | ||
+ | style='font-size:12.0pt;line-height:107%;font-family:"Arial","sans-serif"'> </span></b></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:93.6pt;margin-bottom: | ||
+ | 10.55pt;margin-left:35.8pt;text-indent:-1.0pt;line-height:104%'><b><span | ||
+ | style='font-size:9.0pt;line-height:104%;font-family:"Arial","sans-serif"'>Sommario.</span></b><span | ||
+ | style='font-size:9.0pt;line-height:104%;font-family:"Arial","sans-serif"'> Il | ||
+ | presente paragrafo si riferisce alle prime due lezioni del corso di Fondamenti | ||
+ | di Informatica e Laboratorio di Informatica. </span><span style='font-size: | ||
+ | 10.0pt;line-height:104%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:93.6pt;margin-bottom: | ||
+ | 35.9pt;margin-left:35.8pt;text-indent:-1.0pt;line-height:104%'><b><span | ||
+ | style='font-size:9.0pt;line-height:104%;font-family:"Arial","sans-serif"'>Parole | ||
+ | chiave: </span></b><span style='font-size:9.0pt;line-height:104%;font-family: | ||
+ | "Arial","sans-serif"'>Codifica Binaria, Memoria RAM, Complemento a 2, IEEE | ||
+ | 754 a singola e doppia precisione. </span><span style='font-size:10.0pt; | ||
+ | line-height:104%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <h1>1 Introduzione </h1> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:28.7pt; | ||
+ | margin-left:8.3pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Il fine principale degli argomenti trattati | ||
+ | in queste iniziali lezioni consiste nell'illustrare in quale maniera | ||
+ | l'informazione, per adesso soltanto numerica, viene memorizzata nella memoria | ||
+ | RAM (Random Access Memory) di un sistema di calcolo rispettando standard | ||
+ | condivisi, per poi essere elaborata attraverso un linguaggio di programmazione. | ||
+ | In particolare si tratteranno: la codifica binaria, la codifica esadecimale, le | ||
+ | conversioni di base, il concetto di errore di una codifica, la codifica di | ||
+ | numeri interi con e senza segno in CA2 (complemento a 2), la codifica di numeri | ||
+ | reali in singola e doppia precisione secondo lo standard IEEE 754, gli effetti | ||
+ | sulla dichiarazione delle variabili signed e unsigned di tipo char ed int, e | ||
+ | delle variabili float e double in linguaggio C. </span></p> | ||
+ | |||
+ | <h1>2 La memoria di lavoro </h1> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:7.85pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>La memoria RAM (Random Access Memory) è la | ||
+ | memoria di lavoro (elaborazione) di un sistema di calcolo; per semplicità essa | ||
+ | può essere rappresentata come una tabella organizzata in righe, ciascuna delle | ||
+ | quali (per ora chiamata word) viene suddivisa in 4 colonne o blocchi, da ora in | ||
+ | poi chiamati byte, costituiti da una sequenza di 8 bit (binary digit) ovvero 8 | ||
+ | cifre che possono assumere soltanto valori 0 o 1. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:1.8pt; | ||
+ | margin-left:7.85pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>In generale, ogni programma di elaborazione | ||
+ | si occupa della gestione delle informazioni per unità elementari corrispondenti | ||
+ | alla dimensione dei byte, senza necessariamente scendere al livello di dettaglio | ||
+ | dei singoli bit, per questo motivo si dice che la unità minima indirizzabile | ||
+ | (ovvero dotata di un indirizzo in memoria corrispondente alla posizione in | ||
+ | memoria RAM) è il singolo byte. Il modo più diffuso di numerare i byte, | ||
+ | iniziando sempre dal numero progressi 0, è da destra verso a sinistra (“little | ||
+ | Endian”), laddove il verso dall’alto verso il basso è ovviamente relativo a | ||
+ | come più avanti si dirà essere partizionata la intera memoria RAM. </span></p> | ||
+ | |||
+ | <h1 style='margin-left:.45pt'>3 Le regole per le trasformazioni di base </h1> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:7.85pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Dato un numero, le basi del sistema di | ||
+ | numerazione che si usano per leggere tale numero sono la base 2 (binaria), 8 | ||
+ | (ottale), 16 (esadecimale); assegnata una base del sistema di numerazione, le | ||
+ | cifre sono date da 0 fino a numero base – 1. Dopo la cifra 9, si aggiungono A, | ||
+ | B, C, D, E, F per formare la base di un sistema esadecimale. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.1pt; | ||
+ | margin-left:7.8pt'><span style='font-size:10.0pt;line-height:107%;font-family: | ||
+ | "Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:1.4pt; | ||
+ | margin-left:8.3pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Assegnato un numero codificato in base 2, si | ||
+ | decodifica facilmente in base 10; esempio della codifica chiamata “in binario | ||
+ | puro”: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:7.8pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:5.7pt; | ||
+ | margin-left:7.85pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>(1010.101)<sub>2 </sub>= (1 x 2<sup>3</sup>+ | ||
+ | 0 x 2<sup>2</sup>+1 x 2<sup>1</sup>+ 0 x 2<sup>0 </sup>+ 1 x·2<sup>-1</sup>+ | ||
+ | 0 x 2<sup>-2 </sup>+ 1 x·2<sup>-3</sup>)<sub>10</sub>=(10.625)<sub>10</sub> | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:3.95pt; | ||
+ | margin-left:7.8pt'><span style='font-size:6.0pt;line-height:107%;font-family: | ||
+ | "Arial","sans-serif"'> </span><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:8.3pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><u><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Codifica binaria di un numero</span></u><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>: | ||
+ | per l’operazione inversa, si utilizzano due algoritmi rispettivamente per la | ||
+ | parte intera e decimale del numero: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:1.45pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <h2 style='margin-left:.45pt'>3.1 Algoritmo di Horner - divisioni successive <span | ||
+ | style='font-weight:normal'> </span></h2> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Si prende il numero intero, si mette in | ||
+ | colonna a sinistra, lo si divide per 2, riportando quoziente sotto il dividendo | ||
+ | mentre il resto accanto al dividendo, e così via fino a raggiungere il | ||
+ | quoziente 0. La parte intera del numero in binario è la sequenza dei resti, | ||
+ | presa dal basso verso l’alto. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:18.75pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <h2 style='margin-left:.45pt'>3.2 Algoritmo di Horner - moltiplicazioni | ||
+ | successive <span style='font-weight:normal'> </span></h2> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Si prende il numero decimale, si mette in | ||
+ | colonna a sinistra, lo si moltiplica per 2, riportando: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:58.1pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>1.<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>Se | ||
+ | il prodotto è ≥1, accanto al primo fattore 1 e sotto il complemento del | ||
+ | prodotto </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:58.1pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>2.<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>Se | ||
+ | il prodotto è <1, accanto al primo fattore lo 0 e sotto il prodotto </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Cosi via, fino a raggiungere il prodotto 0. | ||
+ | La sequenza da prendere come parte decimale del numero in binario è la sequenza | ||
+ | di destra presa dall’alto verso il basso. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.15pt; | ||
+ | margin-left:.7pt'><span style='font-size:10.0pt;line-height:107%;font-family: | ||
+ | "Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:1.5pt; | ||
+ | margin-left:.7pt'><span style='font-size:10.0pt;line-height:107%;font-family: | ||
+ | "Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:74.95pt;margin-bottom: | ||
+ | .25pt;margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-.5pt;line-height:107%'><img width=104 height=394 | ||
+ | src="1%20Prima%20Dispensa%20-La%20codifica%20binaria%20dell%20informazione_revisione2015_file/image001.gif" | ||
+ | align=left hspace=12><span style='font-size:10.0pt;line-height:107%;font-family: | ||
+ | "Arial","sans-serif"'>Mentre nell’algoritmo delle divisioni lo 0 si raggiunge | ||
+ | sempre, nell’algoritmo delle moltiplicazioni non è sempre possibile | ||
+ | raggiungerlo e ciò dipende dal concetto di periodo della base; il periodo si | ||
+ | ripete dal momento in cui si trova un numero già trovato in precedenza. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Esempio: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Codifica in binario e ricodifica in decimale | ||
+ | del numero 127.4 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:1.85pt; | ||
+ | margin-left:99.3pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>(127.4)<sub>10 </sub>= (1111111.0110)<sub>2 </sub>= | ||
+ | (127.375)<sub>10 </sub> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:124.9pt;margin-bottom: | ||
+ | .25pt;margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-.5pt;line-height:107%'><span style='font-size:10.0pt;line-height: | ||
+ | 107%;font-family:"Arial","sans-serif"'>Nel momento in cui si accetta un | ||
+ | periodo, si commette un “errore di codifica”. Si definisce: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:0cm; | ||
+ | margin-left:37.45pt;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-18.0pt;line-height:112%'><span style='font-size:10.0pt;line-height: | ||
+ | 112%;font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:112%;font-family:"Arial","sans-serif"'>Errore | ||
+ | assoluto </span><span style='font-size:10.0pt;line-height:112%;font-family: | ||
+ | "Cambria Math","serif"'>𝑒<sub>𝑎</sub></span><span | ||
+ | style='font-size:10.0pt;line-height:112%;font-family:"Arial","sans-serif"'>lo | ||
+ | scarto tra il numero iniziale da codificare e il numero ottenuto dopo la | ||
+ | ricodifica nella stessa base di partenza. Esempio: </span><span | ||
+ | style='font-size:10.0pt;line-height:112%;font-family:"Cambria Math","serif"'>𝑒<sub>𝑎</sub></span><span | ||
+ | style='font-size:10.0pt;line-height:112%;font-family:"Arial","sans-serif"'>= | ||
+ | 127.4 – 127.375 = 0.025 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:37.45pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>Errore | ||
+ | relativo</span><img width=50 height=20 id="Picture 10409" | ||
+ | src="1%20Prima%20Dispensa%20-La%20codifica%20binaria%20dell%20informazione_revisione2015_file/image002.gif"><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>dove | ||
+ | <i>num </i>è il numero iniziale rispetto al quale si è commesso l’errore di | ||
+ | codifica </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:37.95pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Esempio: </span><img width=53 height=21 | ||
+ | id="Picture 10410" | ||
+ | src="1%20Prima%20Dispensa%20-La%20codifica%20binaria%20dell%20informazione_revisione2015_file/image003.gif"><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:37.45pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>Errore | ||
+ | relativo percentuale </span><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Cambria Math","serif"'>𝑒<sub>𝑟% </sub>= 𝑒<sub>𝑟 | ||
+ | </sub>∗ 100</span><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Concetto di <i>range </i>(intervallo di | ||
+ | rappresentazione di un numero): preso un byte, supponendo che, avendo a | ||
+ | disposizione <i>n </i>bit, tutti gli <i>n </i>codificano numeri interi in base | ||
+ | binaria, il <i>range </i>di rappresentazione varia tra </span></p> | ||
+ | |||
+ | <p class=MsoNormal align=center style='margin-top:0cm;margin-right:0cm; | ||
+ | margin-bottom:1.15pt;margin-left:2.55pt;text-align:center'><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Cambria Math","serif"'>[0, | ||
+ | 2<sup>𝑛 </sup>− 1]</span><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Arial","sans-serif"'>. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>La formula deriva dal numero di combinazioni | ||
+ | diverse che si possono ottenere </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:176.75pt;margin-bottom: | ||
+ | 1.9pt;margin-left:1.15pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:221.1pt;line-height:107%'><span style='font-size:10.0pt;line-height: | ||
+ | 107%;font-family:"Cambria Math","serif"'>2<sup>𝑛 </sup>= 256</span><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'> | ||
+ | Tenendo conto che si inizia la numerazione da 0. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Essendo 8 i bit: [0, 255] </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.25pt; | ||
+ | margin-left:.7pt'><span style='font-size:10.0pt;line-height:107%;font-family: | ||
+ | "Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:18.5pt;margin-bottom: | ||
+ | .25pt;margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-.5pt;line-height:107%'><u><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Arial","sans-serif"'>Codifica esadecimale di un | ||
+ | numero</span></u><span style='font-size:10.0pt;line-height:107%;font-family: | ||
+ | "Arial","sans-serif"'>: è necessaria per minimizzare il codice; per eseguirla | ||
+ | si possono utilizzare due metodi: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:58.85pt;margin-bottom: | ||
+ | .25pt;margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height: | ||
+ | 107%;font-family:"Arial","sans-serif"'>1.<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>Gli | ||
+ | algoritmi da usare sono sempre gli algoritmi di Horner, con le opportune | ||
+ | modifiche (in colonna si moltiplica e divide per 16). Infatti i due algoritmi | ||
+ | sono generici, nel senso che, non dipendono dalla base in cui è rappresentato | ||
+ | un numero. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:58.85pt;margin-bottom: | ||
+ | .25pt;margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height: | ||
+ | 107%;font-family:"Arial","sans-serif"'>2.<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>Si | ||
+ | codifica in binario il numero, quindi, essendo </span><span style='font-size: | ||
+ | 10.0pt;line-height:107%;font-family:"Cambria Math","serif"'>2<sup>4 </sup>= 16 </span><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>si | ||
+ | raccolgono le cifre a 4 a 4, a partire dalla virgola e si decodifica da base | ||
+ | binaria a base decimale ciascuno dei blocchi Esempio: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Codifica in esadecimale di 65.25: (65.25)<sub>10 | ||
+ | </sub>= (1000001.01)<sub>2</sub>; </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-bottom:.25pt;line-height:107%'><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>0100 | ||
+ | 0001 .0100 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-bottom:.25pt;line-height:107%'><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>4 1 | ||
+ | .4 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Dunque (65.25)<sub>10 </sub>= (41.4)<sub>16 </sub></span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:2.1pt; | ||
+ | margin-left:.7pt'><span style='font-size:10.0pt;line-height:107%;font-family: | ||
+ | "Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <h2 style='margin-left:.45pt'>3.3 Rappresentazione con modulo e segno (“signed | ||
+ | magnitude” o M&S) </h2> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:3.55pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Per rappresentare un numero con segno, si | ||
+ | usa, per convenzione: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>Un | ||
+ | bit per il segno: 0 per + (più), 1 per – (meno) </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:.25pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>N-1 | ||
+ | bit per il modulo </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:2.75pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Il bit che codifica il segno è definito MSB | ||
+ | (Most Significant Bit, il primo bit, il più significativo). </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:5.15pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>Esempio: n = 8, range [-127,+127] </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.15pt; | ||
+ | margin-left:.95pt;text-indent:-.5pt'><span style='font-size:10.0pt;line-height: | ||
+ | 107%;font-family:"Cambria Math","serif"'>(−11)<sub>10 </sub>= (0011011)<sub>2</sub></span><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal align=center style='margin-top:0cm;margin-right:0cm; | ||
+ | margin-bottom:0cm;margin-left:3.35pt;margin-bottom:.0001pt;text-align:center'><img | ||
+ | width=189 height=35 id="Picture 721" | ||
+ | src="1%20Prima%20Dispensa%20-La%20codifica%20binaria%20dell%20informazione_revisione2015_file/image004.jpg"><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:77.0pt;margin-bottom: | ||
+ | .25pt;margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-.5pt;line-height:107%'><span style='font-size:10.0pt;line-height: | ||
+ | 107%;font-family:"Arial","sans-serif"'>In questo caso le combinazioni si | ||
+ | riducono a 255 causa la doppia rappresentazione dello 0: 10000000 = 00000000 = | ||
+ | 0 e il range è: [-(2<sup>n-1</sup>-1),2<sup>n-1</sup>-1] = [-127,127]. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:1.7pt; | ||
+ | margin-left:.7pt'><span style='font-size:10.0pt;line-height:107%;font-family: | ||
+ | "Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:78.65pt;margin-bottom: | ||
+ | .25pt;margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-.5pt;line-height:142%'><b><span style='font-size:10.0pt; | ||
+ | line-height:142%;font-family:"Times New Roman","serif"'>3.4 L’operazione di | ||
+ | complemento a uno. (CA1) </span></b><span style='font-size:10.0pt;line-height: | ||
+ | 142%;font-family:"Arial","sans-serif"'>E’ un’operazione molto semplice per un | ||
+ | sistema di calcolo ed è alla base dell’operazione di complemento a due grazie | ||
+ | alla quale è possibile rappresentare numeri interi negativi e positivi. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:78.85pt;margin-bottom: | ||
+ | .1pt;margin-left:0cm;line-height:101%'><span style='font-size:10.0pt; | ||
+ | line-height:101%;font-family:"Arial","sans-serif";color:#252525'>Per trovare la | ||
+ | rappresentazione in complemento a uno si invertono semplicemente tutti i bit | ||
+ | della parola. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt'><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Times New Roman","serif"'> | ||
+ | </span></p> | ||
+ | |||
+ | <h2 style='margin-left:.45pt'>3.5 La codifica in complemento a due per i numeri | ||
+ | con segno (CA2) </h2> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:78.5pt;margin-bottom: | ||
+ | .5pt;margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-.5pt;line-height:104%'><span style='font-size:10.0pt;line-height: | ||
+ | 104%;font-family:"Arial","sans-serif"'>Il complemento a due è il metodo più | ||
+ | diffuso per la rappresentazione dei numeri con segno. </span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>Il | ||
+ | valore da utilizzare relativamente al MSB risulta essere il suo opposto (questo | ||
+ | implica che se vale 0 porta a una decodifica di valore uguale alla | ||
+ | rappresentazione in binario puro): </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:1.45pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>00000000=0 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:1.95pt; | ||
+ | margin-left:36.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>00000001=1 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>… </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:4.1pt; | ||
+ | margin-left:36.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>01111111=+127 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>10000000=-1</span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Segoe UI Symbol","sans-serif"'>⋅</span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>2<sup>7</sup>=-128 | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:1.9pt; | ||
+ | margin-left:36.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>10000001=-128+1=-127 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>… </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>11111111=-1 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:1.45pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:1.0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Le combinazioni sono 256 per la | ||
+ | rappresentazione univoca dello 0: ovvero soltanto 00000000 = 0; in questo caso | ||
+ | il range varia tra [-(2<sup>n-1</sup>),2<sup>n-1</sup>-1] = [-128,127]. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:12.15pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:2.55pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Per codificare un numero in complemento | ||
+ | a due: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:18.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | 18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>1.<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>Si | ||
+ | sceglie il range per il quale è possibile codificare il numero e di conseguenza | ||
+ | i bit necessari </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:18.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | 18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>2.<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>Si | ||
+ | rappresenta il valore assoluto del numero in binario </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:18.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | 18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>3.<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>Si | ||
+ | applica l’operazione di complemento a 1 e si somma 1 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:2.15pt; | ||
+ | margin-left:18.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | 18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>4.<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>La | ||
+ | sequenza ottenuta è la codifica del numero iniziale in complemento a due | ||
+ | Esempio: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:2.3pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Si vuole codifica in complemento a 2 il | ||
+ | numero -65 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:3.65pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Il range varia tra [-128,127] </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:2.35pt; | ||
+ | margin-left:.95pt;text-indent:-.5pt'><span style='font-size:10.0pt;line-height: | ||
+ | 107%;font-family:"Cambria Math","serif"'>2<sup>8</sup> 𝑐𝑜𝑚𝑏𝑖𝑛𝑎𝑧𝑖𝑜𝑛𝑖</span><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Times New Roman","serif"'> | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:4.05pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>8 bit necessari </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:270.0pt;margin-bottom: | ||
+ | .5pt;margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-.5pt;line-height:133%'><span style='font-size:10.0pt;line-height: | ||
+ | 133%;font-family:"Times New Roman","serif"'>Il valore assoluto è: </span><span | ||
+ | style='font-size:10.0pt;line-height:133%;font-family:"Cambria Math","serif"'>(65)<sub>10 | ||
+ | </sub>= (01000001)<sub>2</sub></span><span style='font-size:10.0pt;line-height: | ||
+ | 133%;font-family:"Times New Roman","serif"'> Faccio il complemento a 1: | ||
+ | 10111110 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:2.3pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Il complemento a 2 è: 10111110 + 1 = | ||
+ | 10111111 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <h1 style='margin-left:.45pt'>4 Lo standard IEEE 754 </h1> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><u><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'>Standard IEEE 754 | ||
+ | single precision</span></u><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Times New Roman","serif"'>: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Rappresentazione di un numero reale in | ||
+ | 32 bit. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>I 32 bit vengono suddivisi in 3 gruppi: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-bottom:.5pt;line-height:104%'><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>± | ||
+ | esponente mantissa </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-bottom:.5pt;line-height:104%'><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>1 | ||
+ | 8 23 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Il modulo del numero viene codificato in | ||
+ | base binaria usando gli algoritmi di divisione e moltiplicazione successive | ||
+ | evidenziando, nella parte decimale, un periodo ove ci fosse. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>La rappresentazione binaria risultante è | ||
+ | detta “fixed point” (a virgola fissa). </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Si passa alla rappresentazione “floating | ||
+ | point” (a virgola mobile) per determinare mantissa ed esponente. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Si sposta la virgola fino alla sinistra | ||
+ | dell’ultima cifra diversa da zero, cambiando anche l’esponente per | ||
+ | riequilibrare l’ordine di grandezza. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>La parte dopo la virgola indica la | ||
+ | mantissa matematica. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Se si sposta la virgola alla destra | ||
+ | dell’ultima cifra diversa da zero, cambiando anche l’esponente: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>La | ||
+ | parte del numero dopo la virgola indica la mantissa normalizzata che, se | ||
+ | composta da un numero di cifre < 23, ai restanti bit si assegna valore 0 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>Per | ||
+ | codificare l’esponente, si usa la rappresentazione per eccesso: si somma | ||
+ | l’esponente al <i>bias </i>(</span><span style='font-size:10.0pt;line-height: | ||
+ | 104%;font-family:"Cambria Math","serif"'>2<sup>𝑛−1 </sup>−</span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.15pt; | ||
+ | margin-left:37.25pt;text-indent:-.5pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Cambria Math","serif"'>1, 𝑑𝑜𝑣𝑒 | ||
+ | 𝑛 è 𝑖𝑙 𝑛𝑢𝑚𝑒𝑟𝑜 | ||
+ | 𝑑𝑖 𝑏𝑖𝑡 𝑟𝑖𝑠𝑒𝑟𝑣𝑎𝑡𝑖 | ||
+ | 𝑎𝑙𝑙′𝑒𝑠𝑝𝑜𝑛𝑒𝑛𝑡𝑒</span><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Times New Roman","serif"'>) | ||
+ | e quindi si codifica il numero </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Esempio: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:2.3pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Si vuole codificare secondo lo standard | ||
+ | IEEE754 a single precision, il numero -118.625 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>Codifico | ||
+ | la parte intera: </span><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Cambria Math","serif"'>(118)<sub>10 </sub>= (1110110)<sub>2</sub></span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'> | ||
+ | </span><span style='font-size:10.0pt;line-height:104%;font-family:"Segoe UI Symbol","sans-serif"'></span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Arial","sans-serif"'> </span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>Codifico | ||
+ | la parte decimale: </span><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Cambria Math","serif"'>(0.625)<sub>10 </sub>= (.101)<sub>2</sub></span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'> | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>La | ||
+ | rappresentazione in fixed point è: 1110110.101 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>Sposto | ||
+ | la virgola fino alla sinistra dell’ultima cifra diversa da 0 e riequilibrio l’ordine | ||
+ | di grandezza: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:1.8pt; | ||
+ | margin-left:37.25pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>0.1110110101*</span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Cambria Math","serif"'>2<sup>7</sup></span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'> | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>La | ||
+ | mantissa matematica è: 1110110101 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>Sposto | ||
+ | la virgola fino alla destra dell’ultima cifra diversa da zero e riequilibrio | ||
+ | l’ordine di grandezza: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:1.95pt; | ||
+ | margin-left:37.25pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>1.110110101*</span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Cambria Math","serif"'>2<sup>6</sup></span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'> | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>La | ||
+ | mantissa normalizzata è: 110110101 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.15pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt'><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>•<span | ||
+ | style='font:7.0pt "Times New Roman"'> </span></span><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Times New Roman","serif"'>Codifico | ||
+ | l’esponente: </span><span style='font-size:10.0pt;line-height:107%;font-family: | ||
+ | "Cambria Math","serif"'>6 + 2<sup>7 </sup>− 1 = 6 + 127 = 5 + 128 = | ||
+ | 10000101</span><span style='font-size:10.0pt;line-height:107%;font-family:"Times New Roman","serif"'> | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>La | ||
+ | rappresentazione secondo lo standard | ||
+ | IEEE754 a single precision è: | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-bottom:.5pt;line-height:104%'> <span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>1 | ||
+ | 1000101 11011010100000000000000 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-bottom:.5pt;line-height:104%'> <span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>± | ||
+ | esponente mantissa </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>L’ordine di precisione delo standard | ||
+ | IEEE754 è dato dal numero di cifre della mantissa. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Per ottenere una rappresentazione più | ||
+ | precisa si usa lo standard IEEE754 a double precision (64 bit) </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-bottom:.5pt;line-height:104%'><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>± | ||
+ | esponente mantissa </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-bottom:.5pt;line-height:104%'><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>1 | ||
+ | 11 52 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Il metodo di rappresentazione è simile a | ||
+ | quello usato per lo standard a single precision, l’unica cosa che varia è il <i>bias: | ||
+ | </i></span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:13.3pt; | ||
+ | margin-left:.95pt;text-indent:-.5pt'><span style='font-size:10.0pt;line-height: | ||
+ | 107%;font-family:"Cambria Math","serif"'>2<sup>11−1 </sup>− 1 = | ||
+ | 1023</span><span style='font-size:10.0pt;line-height:107%;font-family:"Times New Roman","serif"'> | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:14.15pt; | ||
+ | margin-left:1.65pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:147%'><span style='font-size:10.0pt;line-height:147%; | ||
+ | font-family:"Arial","sans-serif"'>I valori assunti dall'esponente e dalla</span><a | ||
+ | href="https://it.wikipedia.org/wiki/Mantissa"><span style='font-size:10.0pt; | ||
+ | line-height:147%;font-family:"Arial","sans-serif";color:black;text-decoration: | ||
+ | none'> </span></a><a href="https://it.wikipedia.org/wiki/Mantissa"><span | ||
+ | style='font-size:10.0pt;line-height:147%;font-family:"Arial","sans-serif"; | ||
+ | color:black;text-decoration:none'>mantissa</span></a><a | ||
+ | href="https://it.wikipedia.org/wiki/Mantissa"><span style='font-size:10.0pt; | ||
+ | line-height:147%;font-family:"Arial","sans-serif";color:black;text-decoration: | ||
+ | none'> </span></a><span style='font-size:10.0pt;line-height:147%;font-family: | ||
+ | "Arial","sans-serif"'>determinano l'appartenenza del numero ad una di queste | ||
+ | categorie: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:4.2pt; | ||
+ | margin-left:19.15pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>Zeri; | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:4.2pt; | ||
+ | margin-left:19.15pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>Numeri | ||
+ | in forma normale; </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:4.35pt; | ||
+ | margin-left:19.15pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>Numeri | ||
+ | in forma</span><a href="https://it.wikipedia.org/wiki/Numeri_denormalizzati"><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"; | ||
+ | color:black;text-decoration:none'> </span></a><a | ||
+ | href="https://it.wikipedia.org/wiki/Numeri_denormalizzati"><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"; | ||
+ | color:black;text-decoration:none'>denormalizzata</span></a><a | ||
+ | href="https://it.wikipedia.org/wiki/Numeri_denormalizzati"><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"; | ||
+ | color:black;text-decoration:none'>;</span></a><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:4.1pt; | ||
+ | margin-left:19.15pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:107%'><span style='font-size:10.0pt;line-height:107%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>Infiniti; | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:4.8pt;margin-bottom:16.85pt; | ||
+ | margin-left:19.15pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt'><span style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>•<span | ||
+ | style='font:7.0pt "Times New Roman"'> </span></span><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Arial","sans-serif"'>NaN | ||
+ | (<i>not a number</i>). </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:10.45pt; | ||
+ | margin-left:.7pt'><span style='font-size:10.0pt;line-height:107%;font-family: | ||
+ | "Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Arial","sans-serif"'> </span></p> | ||
+ | |||
+ | <table class=TableGrid border=0 cellspacing=0 cellpadding=0 width=428 | ||
+ | style='width:321.1pt;margin-left:81.25pt;border-collapse:collapse'> | ||
+ | <tr style='height:45.45pt'> | ||
+ | <td width=240 style='width:179.7pt;border:solid #AAAAAA 1.0pt;background: | ||
+ | #F2F2F2;padding:0cm 5.75pt 13.85pt 4.8pt;height:45.45pt'> | ||
+ | <p class=MsoNormal align=center style='margin-top:0cm;margin-right:0cm; | ||
+ | margin-bottom:0cm;margin-left:.8pt;margin-bottom:.0001pt;text-align:center; | ||
+ | line-height:normal'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Categoria | ||
+ | </span></b></p> | ||
+ | </td> | ||
+ | <td width=73 style='width:54.4pt;border:solid #AAAAAA 1.0pt;border-left:none; | ||
+ | background:#F2F2F2;padding:0cm 5.75pt 13.85pt 4.8pt;height:45.45pt'> | ||
+ | <p class=MsoNormal align=center style='margin-top:0cm;margin-right:0cm; | ||
+ | margin-bottom:0cm;margin-left:.75pt;margin-bottom:.0001pt;text-align:center; | ||
+ | line-height:normal'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Esp. | ||
+ | </span></b></p> | ||
+ | </td> | ||
+ | <td width=116 style='width:87.05pt;border:solid #AAAAAA 1.0pt;border-left: | ||
+ | none;background:#F2F2F2;padding:0cm 5.75pt 13.85pt 4.8pt;height:45.45pt'> | ||
+ | <p class=MsoNormal align=center style='margin-top:0cm;margin-right:0cm; | ||
+ | margin-bottom:0cm;margin-left:.8pt;margin-bottom:.0001pt;text-align:center; | ||
+ | line-height:normal'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Mantissa | ||
+ | </span></b></p> | ||
+ | </td> | ||
+ | </tr> | ||
+ | <tr style='height:46.3pt'> | ||
+ | <td width=240 valign=bottom style='width:179.7pt;border:solid #AAAAAA 1.0pt; | ||
+ | border-top:none;background:#F2F2F2;padding:0cm 5.75pt 13.85pt 4.8pt; | ||
+ | height:46.3pt'> | ||
+ | <p class=MsoNormal align=center style='margin-top:0cm;margin-right:0cm; | ||
+ | margin-bottom:0cm;margin-left:.65pt;margin-bottom:.0001pt;text-align:center; | ||
+ | line-height:normal'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Zeri | ||
+ | </span></b></p> | ||
+ | </td> | ||
+ | <td width=73 valign=bottom style='width:54.4pt;border-top:none;border-left: | ||
+ | none;border-bottom:solid #AAAAAA 1.0pt;border-right:solid #AAAAAA 1.0pt; | ||
+ | background:#F9F9F9;padding:0cm 5.75pt 13.85pt 4.8pt;height:46.3pt'> | ||
+ | <p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height: | ||
+ | normal'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>0 </span></p> | ||
+ | </td> | ||
+ | <td width=116 valign=bottom style='width:87.05pt;border-top:none;border-left: | ||
+ | none;border-bottom:solid #AAAAAA 1.0pt;border-right:solid #AAAAAA 1.0pt; | ||
+ | background:#F9F9F9;padding:0cm 5.75pt 13.85pt 4.8pt;height:46.3pt'> | ||
+ | <p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height: | ||
+ | normal'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>0 </span></p> | ||
+ | </td> | ||
+ | </tr> | ||
+ | <tr style='height:46.3pt'> | ||
+ | <td width=240 valign=bottom style='width:179.7pt;border:solid #AAAAAA 1.0pt; | ||
+ | border-top:none;background:#F2F2F2;padding:0cm 5.75pt 13.85pt 4.8pt; | ||
+ | height:46.3pt'> | ||
+ | <p class=MsoNormal align=center style='margin-top:0cm;margin-right:0cm; | ||
+ | margin-bottom:0cm;margin-left:.65pt;margin-bottom:.0001pt;text-align:center; | ||
+ | line-height:normal'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Numeri | ||
+ | denormalizzati </span></b></p> | ||
+ | </td> | ||
+ | <td width=73 valign=bottom style='width:54.4pt;border-top:none;border-left: | ||
+ | none;border-bottom:solid #AAAAAA 1.0pt;border-right:solid #AAAAAA 1.0pt; | ||
+ | background:#F9F9F9;padding:0cm 5.75pt 13.85pt 4.8pt;height:46.3pt'> | ||
+ | <p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height: | ||
+ | normal'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>0 </span></p> | ||
+ | </td> | ||
+ | <td width=116 valign=bottom style='width:87.05pt;border-top:none;border-left: | ||
+ | none;border-bottom:solid #AAAAAA 1.0pt;border-right:solid #AAAAAA 1.0pt; | ||
+ | background:#F9F9F9;padding:0cm 5.75pt 13.85pt 4.8pt;height:46.3pt'> | ||
+ | <p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height: | ||
+ | normal'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>non | ||
+ | zero </span></p> | ||
+ | </td> | ||
+ | </tr> | ||
+ | <tr style='height:46.35pt'> | ||
+ | <td width=240 valign=bottom style='width:179.7pt;border:solid #AAAAAA 1.0pt; | ||
+ | border-top:none;background:#F2F2F2;padding:0cm 5.75pt 13.85pt 4.8pt; | ||
+ | height:46.35pt'> | ||
+ | <p class=MsoNormal align=center style='margin-top:0cm;margin-right:0cm; | ||
+ | margin-bottom:0cm;margin-left:.65pt;margin-bottom:.0001pt;text-align:center; | ||
+ | line-height:normal'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Numeri | ||
+ | normalizzati </span></b></p> | ||
+ | </td> | ||
+ | <td width=73 valign=bottom style='width:54.4pt;border-top:none;border-left: | ||
+ | none;border-bottom:double #F9F9F9 6.75pt;border-right:solid #AAAAAA 1.0pt; | ||
+ | background:#F9F9F9;padding:0cm 5.75pt 13.85pt 4.8pt;height:46.35pt'> | ||
+ | <p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height: | ||
+ | normal'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>1-254 | ||
+ | </span></p> | ||
+ | </td> | ||
+ | <td width=116 valign=bottom style='width:87.05pt;border-top:none;border-left: | ||
+ | none;border-bottom:double #F9F9F9 6.75pt;border-right:solid #AAAAAA 1.0pt; | ||
+ | background:#F9F9F9;padding:0cm 5.75pt 13.85pt 4.8pt;height:46.35pt'> | ||
+ | <p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height: | ||
+ | normal'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>qualunque | ||
+ | </span></p> | ||
+ | </td> | ||
+ | </tr> | ||
+ | <tr style='height:46.45pt'> | ||
+ | <td width=240 valign=bottom style='width:179.7pt;border:solid #AAAAAA 1.0pt; | ||
+ | border-top:none;background:#F2F2F2;padding:0cm 5.75pt 13.85pt 4.8pt; | ||
+ | height:46.45pt'> | ||
+ | <p class=MsoNormal align=center style='margin-top:0cm;margin-right:0cm; | ||
+ | margin-bottom:0cm;margin-left:.9pt;margin-bottom:.0001pt;text-align:center; | ||
+ | line-height:normal'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Infiniti | ||
+ | </span></b></p> | ||
+ | </td> | ||
+ | <td width=73 valign=bottom style='width:54.4pt;border-top:none;border-left: | ||
+ | none;border-bottom:solid #AAAAAA 1.0pt;border-right:solid #AAAAAA 1.0pt; | ||
+ | background:#F9F9F9;padding:0cm 5.75pt 13.85pt 4.8pt;height:46.45pt'> | ||
+ | <p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height: | ||
+ | normal'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>255 </span></p> | ||
+ | </td> | ||
+ | <td width=116 valign=bottom style='width:87.05pt;border-top:none;border-left: | ||
+ | none;border-bottom:solid #AAAAAA 1.0pt;border-right:solid #AAAAAA 1.0pt; | ||
+ | background:#F9F9F9;padding:0cm 5.75pt 13.85pt 4.8pt;height:46.45pt'> | ||
+ | <p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height: | ||
+ | normal'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>0 </span></p> | ||
+ | </td> | ||
+ | </tr> | ||
+ | <tr style='height:45.35pt'> | ||
+ | <td width=240 valign=bottom style='width:179.7pt;border:solid #AAAAAA 1.0pt; | ||
+ | border-top:none;background:#F2F2F2;padding:0cm 5.75pt 13.85pt 4.8pt; | ||
+ | height:45.35pt'> | ||
+ | <p class=MsoNormal align=center style='margin-top:0cm;margin-right:0cm; | ||
+ | margin-bottom:0cm;margin-left:.6pt;margin-bottom:.0001pt;text-align:center; | ||
+ | line-height:normal'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Nan | ||
+ | (not a number) </span></b></p> | ||
+ | </td> | ||
+ | <td width=73 valign=bottom style='width:54.4pt;border-top:none;border-left: | ||
+ | none;border-bottom:solid #AAAAAA 1.0pt;border-right:solid #AAAAAA 1.0pt; | ||
+ | background:#F9F9F9;padding:0cm 5.75pt 13.85pt 4.8pt;height:45.35pt'> | ||
+ | <p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height: | ||
+ | normal'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>255 </span></p> | ||
+ | </td> | ||
+ | <td width=116 valign=bottom style='width:87.05pt;border-top:none;border-left: | ||
+ | none;border-bottom:solid #AAAAAA 1.0pt;border-right:solid #AAAAAA 1.0pt; | ||
+ | background:#F9F9F9;padding:0cm 5.75pt 13.85pt 4.8pt;height:45.35pt'> | ||
+ | <p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height: | ||
+ | normal'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>non | ||
+ | zero </span></p> | ||
+ | </td> | ||
+ | </tr> | ||
+ | </table> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:1.8pt; | ||
+ | margin-left:.7pt'><span style='font-size:10.0pt;line-height:107%;font-family: | ||
+ | "Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <h1 style='margin-left:.45pt'>5 Verso il linguaggio C </h1> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:1.85pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Per specificare il tipo di variabile | ||
+ | (tipo di rappresentazione usata per la codifica della variabile) esistono | ||
+ | istruzioni dette </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:4.15pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>“specificatori di tipo”: </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>“char | ||
+ | a”: carattere = variabile a memorizzata in 1 byte, codificata secondo C.A.2 </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>“int | ||
+ | b”: intero = variabile b memorizzata in 2 o 4 byte (4 in VisualC++ 6.0), | ||
+ | codificata secondo C.A.2 </span><span style='font-size:10.0pt;line-height: | ||
+ | 104%;font-family:"Segoe UI Symbol","sans-serif"'></span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Arial","sans-serif"'> </span><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>“float | ||
+ | c”: single = variabile c memorizzata in 4 byte, codificata secondo IEEE754 | ||
+ | single p. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:36.75pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -18.0pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Arial","sans-serif"'>•<span style='font:7.0pt "Times New Roman"'> | ||
+ | </span></span><span style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'>“double | ||
+ | d”: double = variabile d memorizzata in 8 byte, codificata secondo IEEE754 | ||
+ | double p. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:2.0pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Non indicando niente davanti agli | ||
+ | specificatori di tipo, si sottintende “signed”. Per specificare che la | ||
+ | variabile è senza segno, si scrive “unsigned” davanti agli specificatori di | ||
+ | tipo e la codifica avverrà senza segno. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Per dimensionare una variabile, esistono | ||
+ | gli specificatori “short” e “long” da scrivere davanti agli specificatori di | ||
+ | tipo per, rispettivamente, dimezzare o raddoppiare il numero di byte necessari | ||
+ | alla rappresentazione. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:10.2pt;margin-bottom: | ||
+ | 2.25pt;margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-.5pt;line-height:104%'><span style='font-size:10.0pt;line-height: | ||
+ | 104%;font-family:"Times New Roman","serif"'>Per assegnare ad una variabile a il | ||
+ | valore n si utilizza l’assegnazione “ a = n ; ” e, a seconda del tipo | ||
+ | specificato di variabile, il calcolatore memorizzerà il valore n nel primo | ||
+ | pacchetto libero di byte in modo che il primo byte sia multiplo di 4. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:144.8pt;margin-bottom: | ||
+ | .5pt;margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph; | ||
+ | text-indent:-.5pt;line-height:104%'><span style='font-size:10.0pt;line-height: | ||
+ | 104%;font-family:"Times New Roman","serif"'>L’indirizzo di una variabile “a” è | ||
+ | indicato con “&a” ed è quindi multiplo di 4. N.B. la riga di codice a=a+1; | ||
+ | non è un’uguaglianza, ma un’assegnazione! </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.5pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Il calcolatore all’indirizzo &a | ||
+ | sovrascriverà al valore della variabile a, che quindi sarà perso, il valore | ||
+ | incrementato di 1. </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:29.35pt; | ||
+ | margin-left:1.2pt;text-align:justify;text-justify:inter-ideograph;text-indent: | ||
+ | -.5pt;line-height:104%'><b><span style='font-size:10.0pt;line-height:104%; | ||
+ | font-family:"Times New Roman","serif"'>Ringraziamenti.</span></b><span | ||
+ | style='font-size:10.0pt;line-height:104%;font-family:"Times New Roman","serif"'> | ||
+ | Il presente capitolo è stato scritto anche grazie al prezioso contributo dello | ||
+ | studente Donato Mancuso con la successiva revisione del suo collega Pasquale | ||
+ | Bonasia. </span></p> | ||
+ | |||
+ | <h1 style='margin-left:.45pt'>Riferimenti </h1> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.55pt; | ||
+ | margin-left:36.0pt;text-indent:-18.0pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'>1.<span | ||
+ | style='font:7.0pt "Times New Roman"'> </span></span><span | ||
+ | style='font-size:9.0pt;line-height:107%;font-family:"Times New Roman","serif"'>Bevilacqua, | ||
+ | V.: Dispense Teoria 1 e IEEE 754 In: http://www.vitoantoniobevilacqua.it </span><span | ||
+ | style='font-size:10.0pt;line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.9pt; | ||
+ | margin-left:36.0pt;text-indent:-18.0pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'>2.<span | ||
+ | style='font:7.0pt "Times New Roman"'> </span></span><u><span | ||
+ | style='font-size:9.0pt;line-height:107%;font-family:"Times New Roman","serif"'>http://it.wikipedia.org/wiki/IEEE_754</span></u><span | ||
+ | style='font-size:9.0pt;line-height:107%;font-family:"Times New Roman","serif"'> | ||
+ | </span><span style='font-size:10.0pt;line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.9pt; | ||
+ | margin-left:36.0pt;text-indent:-18.0pt'><span style='font-size:10.0pt; | ||
+ | line-height:107%;font-family:"Times New Roman","serif"'>3.<span | ||
+ | style='font:7.0pt "Times New Roman"'> </span></span><u><span | ||
+ | style='font-size:9.0pt;line-height:107%;font-family:"Times New Roman","serif"'>http://it.wikipedia.org/wiki/Ordine_dei_byte</span></u><span | ||
+ | style='font-size:9.0pt;line-height:107%;font-family:"Times New Roman","serif"'> | ||
+ | </span><span style='font-size:10.0pt;line-height:107%;font-family:"Times New Roman","serif"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:12.05pt; | ||
+ | margin-left:.7pt'><b><span style='font-size:8.0pt;line-height:107%;font-family: | ||
+ | "Times New Roman","serif"'>Appendice: Codice in linguaggio C (per ora solo di | ||
+ | test) </span></b></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:76.9pt;margin-bottom: | ||
+ | .15pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:navy'>#include</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'><stdio.h></span><span style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:76.9pt;margin-bottom: | ||
+ | .15pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:navy'>#include</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'><conio.h></span><span style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:silver'> </span><span style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:green'>/*</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>non</span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:silver'> </span><span style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:green'>ANSI</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>C</span><span style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:silver'> </span><span style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:green'>*/</span><span style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:249.75pt;margin-bottom: | ||
+ | .15pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>/*#include</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:green'><math.h></span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:green'>per</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>usare</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:silver'> </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>la</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:green'>funzione</span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:green'>pow*/</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New"'> </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:olive'>int</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>main() { </span><span lang=EN-US style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:olive'>unsigned</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:silver'> </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:olive'>char</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>byte[</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:navy'>4</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>]; | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:silver'> </span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:olive'>unsigned</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:olive'>char</span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New"'>*c; </span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:silver'> </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:olive'>char</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>bit[</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:navy'>9</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>]; | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:silver'> </span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:olive'>int</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>i,j; </span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:olive'>float</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:silver'> </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>a; </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:olive'>float</span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New"'>*p=NULL; </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:441.75pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>a=</span><span style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:navy'>0</span><span style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New"'>; </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:163.35pt;margin-bottom: | ||
+ | .15pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>printf(</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>"Le</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>dimensioni</span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:silver'> </span><span style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:green'>in</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>byte</span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:silver'> </span><span style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:green'>di</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>variabili</span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:silver'> </span><span style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:green'>\n"</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>); </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>printf(</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>"char,</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>int,</span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:silver'> </span><span style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:green'>double</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>e</span><span style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:silver'> </span><span style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:green'>float</span><span style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>valgono</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>\n"</span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>); </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.15pt; | ||
+ | margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>printf(</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>"%d</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:silver'> </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>%d</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:green'>%d</span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:green'>%d\n"</span><span lang=EN-US style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New"'>,</span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:olive'>sizeof</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>(</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:olive'>char</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New"'>),</span><span lang=EN-US style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:olive'>sizeof</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>(</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:olive'>int</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New"'>),</span><span lang=EN-US style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:olive'>sizeof</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>(</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:olive'>float</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New"'>),</span><span lang=EN-US style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:olive'>sizeof</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>(</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:olive'>double</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New"'>)); </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:451.35pt;margin-bottom: | ||
+ | .15pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:olive'>do</span><span style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New"'> </span><span style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>{ </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:264.1pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>printf(</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>"inserisci</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>a</span><span style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:silver'> </span><span style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:green'>=</span><span style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>"</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>); </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>scanf(</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>"%f"</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>,&a); </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:76.9pt;margin-bottom: | ||
+ | .15pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>/*a=(float)pow(2,</span><span style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:silver'> </span><span style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:green'>-2);utile</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>per</span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:silver'> </span><span style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:green'>trovare</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>il</span><span style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:silver'> </span><span style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:green'>range</span><span style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>di</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>rappresentazione*/</span><span style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New"'> </span><span style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>p=&a; </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.15pt; | ||
+ | margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>c=(</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:olive'>unsigned</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:silver'> </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:olive'>char</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>*)p; </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:211.35pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New"'>printf(</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:green'>"%d</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New";color:green'>%d</span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:green'>%d</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>%d\n"</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New"'>,*(c+</span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:navy'>3</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>),*(c+</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:navy'>2</span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>),*(c+</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:navy'>1</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>),*c); | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:silver'> </span><span lang=EN-US style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New"'>printf(</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>"\n"</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New"'>); </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:olive'>for</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New"'>(i=</span><span lang=EN-US style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:navy'>0</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>;i<</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:navy'>4</span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>;i++) </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:264.1pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New"'>{ </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:316.9pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New"'>byte[i]=*(c+</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:navy'>3</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>-i); | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:silver'> </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>j=</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:navy'>0</span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>; </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:264.1pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:olive'>while</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>(byte[i]></span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:navy'>0</span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>) </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:264.1pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New"'>{ </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:312.15pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New"'>bit[j]=byte[i]%</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:navy'>2</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>; | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:silver'> </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>byte[i]=</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>byte[i]/</span><span lang=EN-US style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:navy'>2</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>; | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:silver'> </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>j=j+</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:navy'>1</span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>; </span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>} | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:264.1pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span lang=EN-US style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New";color:olive'>for</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New"'>(;j<</span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:navy'>8</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>;bit[j++]=</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:navy'>0</span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>); </span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:olive'>for</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New"'>(j=</span><span lang=EN-US style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:navy'>7</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>;j>=</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:navy'>0</span><span lang=EN-US style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>;j--) </span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>printf(</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>"%d"</span><span lang=EN-US style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New"'>,bit[j]); </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>printf(</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>"</span><span lang=EN-US style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:silver'> </span><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>"</span><span | ||
+ | lang=EN-US style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>); | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:316.95pt;margin-bottom: | ||
+ | .15pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span lang=EN-US | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>} | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:silver'> </span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>printf(</span><span style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:green'>"\n</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>\n"</span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>); </span><span style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>printf(</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:green'>"altro</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:green'>numero?\n"</span><span style='font-size:8.0pt;line-height: | ||
+ | 103%;font-family:"Courier New"'>); </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:456.15pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'> </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>} | ||
+ | </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:264.1pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:olive'>while</span><span style='font-size:8.0pt;line-height:103%; | ||
+ | font-family:"Courier New"'>(getch()!=</span><span style='font-size:8.0pt; | ||
+ | line-height:103%;font-family:"Courier New";color:green'>'n'</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>); </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:0cm; | ||
+ | margin-left:.7pt;margin-bottom:.0001pt'><span style='font-size:8.0pt; | ||
+ | line-height:107%;font-family:"Courier New"'> </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:0cm;margin-bottom:.15pt; | ||
+ | margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span style='font-size: | ||
+ | 8.0pt;line-height:103%;font-family:"Courier New";color:silver'> </span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:olive'>return</span><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New";color:silver'> | ||
+ | </span><span style='font-size:8.0pt;line-height:103%;font-family:"Courier New"; | ||
+ | color:navy'>0</span><span style='font-size:8.0pt;line-height:103%;font-family: | ||
+ | "Courier New"'>; </span></p> | ||
+ | |||
+ | <p class=MsoNormal style='margin-top:0cm;margin-right:264.1pt;margin-bottom: | ||
+ | .2pt;margin-left:.45pt;text-indent:-.5pt;line-height:103%'><span | ||
+ | style='font-size:8.0pt;line-height:103%;font-family:"Courier New"'>} </span></p> | ||
+ | |||
+ | </div> | ||
+ | |||
+ | </body> | ||
+ | |||
+ | </html> |
Versione delle 13:17, 1 ott 2016
<html>
<head> <meta http-equiv=Content-Type content="text/html; charset=windows-1252"> <meta name=Generator content="Microsoft Word 14 (filtered)"> <title>Microsoft Word - La codifica binaria dell'informazione_revisione2012.doc</title> <style> </style>
</head>
<body lang=IT>
La codifica binaria della informazione
Vitoantonio Bevilacqua
bevilacqua@poliba.it
Sommario. Il presente paragrafo si riferisce alle prime due lezioni del corso di Fondamenti di Informatica e Laboratorio di Informatica.
Parole chiave: Codifica Binaria, Memoria RAM, Complemento a 2, IEEE 754 a singola e doppia precisione.
Indice
[nascondi]1 Introduzione
Il fine principale degli argomenti trattati in queste iniziali lezioni consiste nell'illustrare in quale maniera l'informazione, per adesso soltanto numerica, viene memorizzata nella memoria RAM (Random Access Memory) di un sistema di calcolo rispettando standard condivisi, per poi essere elaborata attraverso un linguaggio di programmazione. In particolare si tratteranno: la codifica binaria, la codifica esadecimale, le conversioni di base, il concetto di errore di una codifica, la codifica di numeri interi con e senza segno in CA2 (complemento a 2), la codifica di numeri reali in singola e doppia precisione secondo lo standard IEEE 754, gli effetti sulla dichiarazione delle variabili signed e unsigned di tipo char ed int, e delle variabili float e double in linguaggio C.
2 La memoria di lavoro
La memoria RAM (Random Access Memory) è la memoria di lavoro (elaborazione) di un sistema di calcolo; per semplicità essa può essere rappresentata come una tabella organizzata in righe, ciascuna delle quali (per ora chiamata word) viene suddivisa in 4 colonne o blocchi, da ora in poi chiamati byte, costituiti da una sequenza di 8 bit (binary digit) ovvero 8 cifre che possono assumere soltanto valori 0 o 1.
In generale, ogni programma di elaborazione si occupa della gestione delle informazioni per unità elementari corrispondenti alla dimensione dei byte, senza necessariamente scendere al livello di dettaglio dei singoli bit, per questo motivo si dice che la unità minima indirizzabile (ovvero dotata di un indirizzo in memoria corrispondente alla posizione in memoria RAM) è il singolo byte. Il modo più diffuso di numerare i byte, iniziando sempre dal numero progressi 0, è da destra verso a sinistra (“little Endian”), laddove il verso dall’alto verso il basso è ovviamente relativo a come più avanti si dirà essere partizionata la intera memoria RAM.
3 Le regole per le trasformazioni di base
Dato un numero, le basi del sistema di numerazione che si usano per leggere tale numero sono la base 2 (binaria), 8 (ottale), 16 (esadecimale); assegnata una base del sistema di numerazione, le cifre sono date da 0 fino a numero base – 1. Dopo la cifra 9, si aggiungono A, B, C, D, E, F per formare la base di un sistema esadecimale.
Assegnato un numero codificato in base 2, si decodifica facilmente in base 10; esempio della codifica chiamata “in binario puro”:
(1010.101)2 = (1 x 23+ 0 x 22+1 x 21+ 0 x 20 + 1 x·2-1+ 0 x 2-2 + 1 x·2-3)10=(10.625)10
Codifica binaria di un numero: per l’operazione inversa, si utilizzano due algoritmi rispettivamente per la parte intera e decimale del numero:
3.1 Algoritmo di Horner - divisioni successive
Si prende il numero intero, si mette in colonna a sinistra, lo si divide per 2, riportando quoziente sotto il dividendo mentre il resto accanto al dividendo, e così via fino a raggiungere il quoziente 0. La parte intera del numero in binario è la sequenza dei resti, presa dal basso verso l’alto.
3.2 Algoritmo di Horner - moltiplicazioni successive
Si prende il numero decimale, si mette in colonna a sinistra, lo si moltiplica per 2, riportando:
1. Se il prodotto è ≥1, accanto al primo fattore 1 e sotto il complemento del prodotto
2. Se il prodotto è <1, accanto al primo fattore lo 0 e sotto il prodotto
Cosi via, fino a raggiungere il prodotto 0. La sequenza da prendere come parte decimale del numero in binario è la sequenza di destra presa dall’alto verso il basso.
<img width=104 height=394 src="1%20Prima%20Dispensa%20-La%20codifica%20binaria%20dell%20informazione_revisione2015_file/image001.gif" align=left hspace=12>Mentre nell’algoritmo delle divisioni lo 0 si raggiunge sempre, nell’algoritmo delle moltiplicazioni non è sempre possibile raggiungerlo e ciò dipende dal concetto di periodo della base; il periodo si ripete dal momento in cui si trova un numero già trovato in precedenza.
Esempio:
Codifica in binario e ricodifica in decimale del numero 127.4
(127.4)10 = (1111111.0110)2 = (127.375)10
Nel momento in cui si accetta un periodo, si commette un “errore di codifica”. Si definisce:
• Errore assoluto 𝑒𝑎lo scarto tra il numero iniziale da codificare e il numero ottenuto dopo la ricodifica nella stessa base di partenza. Esempio: 𝑒𝑎= 127.4 – 127.375 = 0.025
• Errore relativo<img width=50 height=20 id="Picture 10409" src="1%20Prima%20Dispensa%20-La%20codifica%20binaria%20dell%20informazione_revisione2015_file/image002.gif">dove num è il numero iniziale rispetto al quale si è commesso l’errore di codifica
Esempio: <img width=53 height=21 id="Picture 10410" src="1%20Prima%20Dispensa%20-La%20codifica%20binaria%20dell%20informazione_revisione2015_file/image003.gif">
• Errore relativo percentuale 𝑒𝑟% = 𝑒𝑟 ∗ 100
Concetto di range (intervallo di rappresentazione di un numero): preso un byte, supponendo che, avendo a disposizione n bit, tutti gli n codificano numeri interi in base binaria, il range di rappresentazione varia tra
[0, 2𝑛 − 1].
La formula deriva dal numero di combinazioni diverse che si possono ottenere
2𝑛 = 256 Tenendo conto che si inizia la numerazione da 0.
Essendo 8 i bit: [0, 255]
Codifica esadecimale di un numero: è necessaria per minimizzare il codice; per eseguirla si possono utilizzare due metodi:
1. Gli algoritmi da usare sono sempre gli algoritmi di Horner, con le opportune modifiche (in colonna si moltiplica e divide per 16). Infatti i due algoritmi sono generici, nel senso che, non dipendono dalla base in cui è rappresentato un numero.
2. Si codifica in binario il numero, quindi, essendo 24 = 16 si raccolgono le cifre a 4 a 4, a partire dalla virgola e si decodifica da base binaria a base decimale ciascuno dei blocchi Esempio:
Codifica in esadecimale di 65.25: (65.25)10 = (1000001.01)2;
0100 0001 .0100
4 1 .4
Dunque (65.25)10 = (41.4)16
3.3 Rappresentazione con modulo e segno (“signed magnitude” o M&S)
Per rappresentare un numero con segno, si usa, per convenzione:
• Un bit per il segno: 0 per + (più), 1 per – (meno)
• N-1 bit per il modulo
Il bit che codifica il segno è definito MSB (Most Significant Bit, il primo bit, il più significativo).
Esempio: n = 8, range [-127,+127]
(−11)10 = (0011011)2
<img width=189 height=35 id="Picture 721" src="1%20Prima%20Dispensa%20-La%20codifica%20binaria%20dell%20informazione_revisione2015_file/image004.jpg">
In questo caso le combinazioni si riducono a 255 causa la doppia rappresentazione dello 0: 10000000 = 00000000 = 0 e il range è: [-(2n-1-1),2n-1-1] = [-127,127].
3.4 L’operazione di complemento a uno. (CA1) E’ un’operazione molto semplice per un sistema di calcolo ed è alla base dell’operazione di complemento a due grazie alla quale è possibile rappresentare numeri interi negativi e positivi.
Per trovare la rappresentazione in complemento a uno si invertono semplicemente tutti i bit della parola.
3.5 La codifica in complemento a due per i numeri con segno (CA2)
Il complemento a due è il metodo più diffuso per la rappresentazione dei numeri con segno. Il valore da utilizzare relativamente al MSB risulta essere il suo opposto (questo implica che se vale 0 porta a una decodifica di valore uguale alla rappresentazione in binario puro):
00000000=0
00000001=1
…
01111111=+127
10000000=-1⋅27=-128
10000001=-128+1=-127
…
11111111=-1
Le combinazioni sono 256 per la rappresentazione univoca dello 0: ovvero soltanto 00000000 = 0; in questo caso il range varia tra [-(2n-1),2n-1-1] = [-128,127].
Per codificare un numero in complemento a due:
1. Si sceglie il range per il quale è possibile codificare il numero e di conseguenza i bit necessari
2. Si rappresenta il valore assoluto del numero in binario
3. Si applica l’operazione di complemento a 1 e si somma 1
4. La sequenza ottenuta è la codifica del numero iniziale in complemento a due Esempio:
Si vuole codifica in complemento a 2 il numero -65
Il range varia tra [-128,127]
28 𝑐𝑜𝑚𝑏𝑖𝑛𝑎𝑧𝑖𝑜𝑛𝑖
8 bit necessari
Il valore assoluto è: (65)10 = (01000001)2 Faccio il complemento a 1: 10111110
Il complemento a 2 è: 10111110 + 1 = 10111111
4 Lo standard IEEE 754
Standard IEEE 754 single precision:
Rappresentazione di un numero reale in 32 bit.
I 32 bit vengono suddivisi in 3 gruppi:
± esponente mantissa
1 8 23
Il modulo del numero viene codificato in base binaria usando gli algoritmi di divisione e moltiplicazione successive evidenziando, nella parte decimale, un periodo ove ci fosse.
La rappresentazione binaria risultante è detta “fixed point” (a virgola fissa).
Si passa alla rappresentazione “floating point” (a virgola mobile) per determinare mantissa ed esponente.
Si sposta la virgola fino alla sinistra dell’ultima cifra diversa da zero, cambiando anche l’esponente per riequilibrare l’ordine di grandezza.
La parte dopo la virgola indica la mantissa matematica.
Se si sposta la virgola alla destra dell’ultima cifra diversa da zero, cambiando anche l’esponente:
• La parte del numero dopo la virgola indica la mantissa normalizzata che, se composta da un numero di cifre < 23, ai restanti bit si assegna valore 0
• Per codificare l’esponente, si usa la rappresentazione per eccesso: si somma l’esponente al bias (2𝑛−1 −
1, 𝑑𝑜𝑣𝑒 𝑛 è 𝑖𝑙 𝑛𝑢𝑚𝑒𝑟𝑜 𝑑𝑖 𝑏𝑖𝑡 𝑟𝑖𝑠𝑒𝑟𝑣𝑎𝑡𝑖 𝑎𝑙𝑙′𝑒𝑠𝑝𝑜𝑛𝑒𝑛𝑡𝑒) e quindi si codifica il numero
Esempio:
Si vuole codificare secondo lo standard IEEE754 a single precision, il numero -118.625
• Codifico la parte intera: (118)10 = (1110110)2 Codifico la parte decimale: (0.625)10 = (.101)2
• La rappresentazione in fixed point è: 1110110.101
• Sposto la virgola fino alla sinistra dell’ultima cifra diversa da 0 e riequilibrio l’ordine di grandezza:
0.1110110101*27
• La mantissa matematica è: 1110110101
• Sposto la virgola fino alla destra dell’ultima cifra diversa da zero e riequilibrio l’ordine di grandezza:
1.110110101*26
• La mantissa normalizzata è: 110110101
• Codifico l’esponente: 6 + 27 − 1 = 6 + 127 = 5 + 128 = 10000101
• La rappresentazione secondo lo standard IEEE754 a single precision è:
1 1000101 11011010100000000000000
± esponente mantissa
L’ordine di precisione delo standard IEEE754 è dato dal numero di cifre della mantissa.
Per ottenere una rappresentazione più precisa si usa lo standard IEEE754 a double precision (64 bit)
± esponente mantissa
1 11 52
Il metodo di rappresentazione è simile a quello usato per lo standard a single precision, l’unica cosa che varia è il bias:
211−1 − 1 = 1023
I valori assunti dall'esponente e dalla<a href="https://it.wikipedia.org/wiki/Mantissa"> </a><a href="https://it.wikipedia.org/wiki/Mantissa">mantissa</a><a href="https://it.wikipedia.org/wiki/Mantissa"> </a>determinano l'appartenenza del numero ad una di queste categorie:
• Zeri;
• Numeri in forma normale;
• Numeri in forma<a href="https://it.wikipedia.org/wiki/Numeri_denormalizzati"> </a><a href="https://it.wikipedia.org/wiki/Numeri_denormalizzati">denormalizzata</a><a href="https://it.wikipedia.org/wiki/Numeri_denormalizzati">;</a>
• Infiniti;
• NaN (not a number).
Categoria |
Esp. |
Mantissa |
Zeri |
0 |
0 |
Numeri denormalizzati |
0 |
non zero |
Numeri normalizzati |
1-254 |
qualunque |
Infiniti |
255 |
0 |
Nan (not a number) |
255 |
non zero |
5 Verso il linguaggio C
Per specificare il tipo di variabile (tipo di rappresentazione usata per la codifica della variabile) esistono istruzioni dette
“specificatori di tipo”:
• “char a”: carattere = variabile a memorizzata in 1 byte, codificata secondo C.A.2
• “int b”: intero = variabile b memorizzata in 2 o 4 byte (4 in VisualC++ 6.0), codificata secondo C.A.2 “float c”: single = variabile c memorizzata in 4 byte, codificata secondo IEEE754 single p.
• “double d”: double = variabile d memorizzata in 8 byte, codificata secondo IEEE754 double p.
Non indicando niente davanti agli specificatori di tipo, si sottintende “signed”. Per specificare che la variabile è senza segno, si scrive “unsigned” davanti agli specificatori di tipo e la codifica avverrà senza segno.
Per dimensionare una variabile, esistono gli specificatori “short” e “long” da scrivere davanti agli specificatori di tipo per, rispettivamente, dimezzare o raddoppiare il numero di byte necessari alla rappresentazione.
Per assegnare ad una variabile a il valore n si utilizza l’assegnazione “ a = n ; ” e, a seconda del tipo specificato di variabile, il calcolatore memorizzerà il valore n nel primo pacchetto libero di byte in modo che il primo byte sia multiplo di 4.
L’indirizzo di una variabile “a” è indicato con “&a” ed è quindi multiplo di 4. N.B. la riga di codice a=a+1; non è un’uguaglianza, ma un’assegnazione!
Il calcolatore all’indirizzo &a sovrascriverà al valore della variabile a, che quindi sarà perso, il valore incrementato di 1.
Ringraziamenti. Il presente capitolo è stato scritto anche grazie al prezioso contributo dello studente Donato Mancuso con la successiva revisione del suo collega Pasquale Bonasia.
Riferimenti
1. Bevilacqua, V.: Dispense Teoria 1 e IEEE 754 In: http://www.vitoantoniobevilacqua.it
2. http://it.wikipedia.org/wiki/IEEE_754
3. http://it.wikipedia.org/wiki/Ordine_dei_byte
Appendice: Codice in linguaggio C (per ora solo di test)
#include <stdio.h>
#include <conio.h> /* non ANSI C */
/*#include <math.h> per usare la funzione pow*/ int main() { unsigned char byte[4]; unsigned char *c; char bit[9]; int i,j; float a; float *p=NULL;
a=0;
printf("Le dimensioni in byte di variabili \n"); printf("char, int, double e float valgono \n");
printf("%d %d %d %d\n",sizeof(char),sizeof(int),sizeof(float),sizeof(double));
do {
printf("inserisci a = "); scanf("%f",&a);
/*a=(float)pow(2, -2);utile per trovare il range di rappresentazione*/ p=&a;
c=(unsigned char *)p;
printf("%d %d %d %d\n",*(c+3),*(c+2),*(c+1),*c); printf("\n"); for(i=0;i<4;i++)
{
byte[i]=*(c+3-i); j=0;
while (byte[i]>0)
{
bit[j]=byte[i]%2; byte[i]= byte[i]/2; j=j+1; }
for(;j<8;bit[j++]=0); for(j=7;j>=0;j--) printf("%d",bit[j]); printf(" ");
} printf("\n \n"); printf("altro numero?\n");
}
while(getch()!='n');
return 0;
}
</body>
</html>