SlideShare uma empresa Scribd logo
1 de 7
Baixar para ler offline
Représentation des
                                                             nombres entiers
                                                                        Eduardo Sanchez



                                                  Ecole Polytechnique Fédérale de Lausanne




Représentation des nombres entiers signés
 Représentation signe-magnitude:
 Le bit de poids fort indique le signe (0 si positif) et les bits restants la
 valeur du nombre.
 Avec n bits on peut représenter des entiers entre:
                  -(2n-1-1) et +(2n-1-1)
 Deux représentations sont possibles pour zéro
 Exemple avec n=4:

              5 = 0101          -5 = 1101                                    signe

                                                                             magnitude
                  0 = 0000 = 1000

                                         Eduardo Sanchez
Page 2                       Ecole Polytechnique Fédérale de Lausanne
Exemples d'opérations arithmétiques (avec n=4):
             5          0101                       résultat faux (0):
            +3          0011                   dépassement de capacité
             8          1000

         la soustraction devrait pouvoir être traitée comme une addition:
                                   5 - 3 = 5 + (-3)

                5        0101
               -3        1011                          résultat faux (0)
                2        0000



                                              Eduardo Sanchez
Page 3                            Ecole Polytechnique Fédérale de Lausanne




     Représentation complément à deux:
     Le complément à deux d’un nombre est égal à l'inverse du
     nombre plus 1. Par exemple, le complément à deux de 0101 est
     (1010+1)=1011
     Dans ce système, un nombre négatif est le complément à deux
     du même nombre positif. Le bit de poids fort d'un nombre
     négatif est égal à 1
     Avec n bits on peut représenter des entiers entre:
                      -(2n-1) et +(2n-1-1)
                                                                             n 2
                                                                 n 1                      i
                x x
                  n 1    n   2
                               ... x 0 =        x   n 1     2          +            x 2
                                                                                     i
                                                                             i= 0

     Une seule représentation est possible pour zéro


                                              Eduardo Sanchez
Page 4                            Ecole Polytechnique Fédérale de Lausanne
2n



                       +2n-1                                               2n-1       non signé



         complément       0                                                0
            à2


                       -2n-1


                                            Eduardo Sanchez
Page 5                          Ecole Polytechnique Fédérale de Lausanne




     Exemple avec n=4:

                5 = 0101                         -5 = 1011
                3 = 0011                         -3 = 1101
                                                                                       signe
                8 = impossible                   -8 = 1000

                               0 = 0000
     Si n=4:

                                                                               signe-magnitude
               -8 -7             0                           7    8

                                                                               complément à 2
               -8 -7             0                           7    8




                                            Eduardo Sanchez
Page 6                          Ecole Polytechnique Fédérale de Lausanne
non signé                signe-               complément à 2
                                                  magnitude
                0000          0                          0                    0
                0001          1                          1                    1
                0010          2                          2                    2
                0011          3                          3                    3
                0100          4                          4                    4
                0101          5                          5                    5
                0110          6                          6                    6
                0111          7                          7                    7
                1000          8                          0                    -8
                1001          9                          -1                   -7
                1010          10                         -2                   -6
                1011          11                         -3                   -5
                1100          12                         -4                   -4
                1101          13                         -5                   -3
                1110          14                         -6                   -2
                1111          15                         -7                   -1
                                         Eduardo Sanchez
Page 7                       Ecole Polytechnique Fédérale de Lausanne




     Exemples d'opérations arithmétiques (avec n=4):
               5       0101                  résultat faux (-8):
              +3       0011               dépassement de capacité
               8       1000

             la soustraction peut être traitée comme une addition:
                                 5 - 3 = 5 + (-3)

               5       0101
              -3       1101                        résultat correct
               2       0010



                                         Eduardo Sanchez
Page 8                       Ecole Polytechnique Fédérale de Lausanne
Les opérations d'addition et de soustraction sont simplifiées en
     complément à deux:


                                  A-B                          A+B



                                 B = B+1




                                                           Z = A+B




                                               Eduardo Sanchez
Page 9                             Ecole Polytechnique Fédérale de Lausanne




     Traitement du dépassement de capacité pour une addition:
          • si les deux opérandes sont du même signe:
            dépassement si le résultat est du signe opposé
          • si les deux opérandes sont de signe opposé:
            il n'y a jamais de dépassement de capacité
     Plus formellement, pour des nombres n bits, signés en
     complément à 2:
                    overflow = cn cn-1
     Exemple:
                                 0111 carry
                          5       0101
                                                                     ov = cn   cn-1= 0   1=1
                         +3      +0011
                          8       1000

                                               Eduardo Sanchez
Page 10                            Ecole Polytechnique Fédérale de Lausanne
Si nous avons deux entiers signés, x et y, en format complément à
     2 sur n bits, leur addition présente 3 cas:
          • si x+y 2n-1, il y a un dépassement de capacité positif
          • si -2n-1 x+y < 2n-1, le résultat est correct
          • si x+y < -2n-1, il y a un dépassement de capacité négatif
     Pour n=4, les résultats possibles de l'addition de deux nombres
     signés sont illustrés par la figure suivante




                                                                Eduardo Sanchez
Page 11                                             Ecole Polytechnique Fédérale de Lausanne




                                                                résultat
             dépassement                                        correct
             négatif                                                                                         dépassement
                                                                                                             positif

                   8

                   6

                    4

                    2

                    0
                                                                                                                 6
                    -2                                                                                       4
                                                                                                         2
                    -4
                                                                                                     0
                    -6
                                                                                                -2
                       -8                                                                  -4
                            -8
                                 -6                                                 -6
                                      -4
                                           -2
                                                0                           -8
                                                     2
                                                          4
                                                                6



                                                                Eduardo Sanchez
Page 12                                             Ecole Polytechnique Fédérale de Lausanne
Extension de signe:
     Si l'on veut passer un entier signé x d'un format n bits vers un
     format n+k bits, en gardant la même valeur, il suffit de faire une
     extension de signe: le bit de signe est répété sur les nouveaux k
     bits de poids fort

                                                                       n
                                                                       …

                                                                       …
                           …

                     …                                                 …
                     k                                                 n


                                        Eduardo Sanchez
Page 13                     Ecole Polytechnique Fédérale de Lausanne

Mais conteúdo relacionado

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

3.entiers

  • 1. Représentation des nombres entiers Eduardo Sanchez Ecole Polytechnique Fédérale de Lausanne Représentation des nombres entiers signés Représentation signe-magnitude: Le bit de poids fort indique le signe (0 si positif) et les bits restants la valeur du nombre. Avec n bits on peut représenter des entiers entre: -(2n-1-1) et +(2n-1-1) Deux représentations sont possibles pour zéro Exemple avec n=4: 5 = 0101 -5 = 1101 signe magnitude 0 = 0000 = 1000 Eduardo Sanchez Page 2 Ecole Polytechnique Fédérale de Lausanne
  • 2. Exemples d'opérations arithmétiques (avec n=4): 5 0101 résultat faux (0): +3 0011 dépassement de capacité 8 1000 la soustraction devrait pouvoir être traitée comme une addition: 5 - 3 = 5 + (-3) 5 0101 -3 1011 résultat faux (0) 2 0000 Eduardo Sanchez Page 3 Ecole Polytechnique Fédérale de Lausanne Représentation complément à deux: Le complément à deux d’un nombre est égal à l'inverse du nombre plus 1. Par exemple, le complément à deux de 0101 est (1010+1)=1011 Dans ce système, un nombre négatif est le complément à deux du même nombre positif. Le bit de poids fort d'un nombre négatif est égal à 1 Avec n bits on peut représenter des entiers entre: -(2n-1) et +(2n-1-1) n 2 n 1 i x x n 1 n 2 ... x 0 = x n 1 2 + x 2 i i= 0 Une seule représentation est possible pour zéro Eduardo Sanchez Page 4 Ecole Polytechnique Fédérale de Lausanne
  • 3. 2n +2n-1 2n-1 non signé complément 0 0 à2 -2n-1 Eduardo Sanchez Page 5 Ecole Polytechnique Fédérale de Lausanne Exemple avec n=4: 5 = 0101 -5 = 1011 3 = 0011 -3 = 1101 signe 8 = impossible -8 = 1000 0 = 0000 Si n=4: signe-magnitude -8 -7 0 7 8 complément à 2 -8 -7 0 7 8 Eduardo Sanchez Page 6 Ecole Polytechnique Fédérale de Lausanne
  • 4. non signé signe- complément à 2 magnitude 0000 0 0 0 0001 1 1 1 0010 2 2 2 0011 3 3 3 0100 4 4 4 0101 5 5 5 0110 6 6 6 0111 7 7 7 1000 8 0 -8 1001 9 -1 -7 1010 10 -2 -6 1011 11 -3 -5 1100 12 -4 -4 1101 13 -5 -3 1110 14 -6 -2 1111 15 -7 -1 Eduardo Sanchez Page 7 Ecole Polytechnique Fédérale de Lausanne Exemples d'opérations arithmétiques (avec n=4): 5 0101 résultat faux (-8): +3 0011 dépassement de capacité 8 1000 la soustraction peut être traitée comme une addition: 5 - 3 = 5 + (-3) 5 0101 -3 1101 résultat correct 2 0010 Eduardo Sanchez Page 8 Ecole Polytechnique Fédérale de Lausanne
  • 5. Les opérations d'addition et de soustraction sont simplifiées en complément à deux: A-B A+B B = B+1 Z = A+B Eduardo Sanchez Page 9 Ecole Polytechnique Fédérale de Lausanne Traitement du dépassement de capacité pour une addition: • si les deux opérandes sont du même signe: dépassement si le résultat est du signe opposé • si les deux opérandes sont de signe opposé: il n'y a jamais de dépassement de capacité Plus formellement, pour des nombres n bits, signés en complément à 2: overflow = cn cn-1 Exemple: 0111 carry 5 0101 ov = cn cn-1= 0 1=1 +3 +0011 8 1000 Eduardo Sanchez Page 10 Ecole Polytechnique Fédérale de Lausanne
  • 6. Si nous avons deux entiers signés, x et y, en format complément à 2 sur n bits, leur addition présente 3 cas: • si x+y 2n-1, il y a un dépassement de capacité positif • si -2n-1 x+y < 2n-1, le résultat est correct • si x+y < -2n-1, il y a un dépassement de capacité négatif Pour n=4, les résultats possibles de l'addition de deux nombres signés sont illustrés par la figure suivante Eduardo Sanchez Page 11 Ecole Polytechnique Fédérale de Lausanne résultat dépassement correct négatif dépassement positif 8 6 4 2 0 6 -2 4 2 -4 0 -6 -2 -8 -4 -8 -6 -6 -4 -2 0 -8 2 4 6 Eduardo Sanchez Page 12 Ecole Polytechnique Fédérale de Lausanne
  • 7. Extension de signe: Si l'on veut passer un entier signé x d'un format n bits vers un format n+k bits, en gardant la même valeur, il suffit de faire une extension de signe: le bit de signe est répété sur les nouveaux k bits de poids fort n … … … … … k n Eduardo Sanchez Page 13 Ecole Polytechnique Fédérale de Lausanne