• Aucun résultat trouvé

In G en er al ( b in ar y )

N/A
N/A
Protected

Academic year: 2022

Partager "In G en er al ( b in ar y )"

Copied!
8
0
0

Texte intégral

(1)

R E P R E S E N T IN G IN T E G E R D A T A

Englander Ch. 4 ITEC 1011Introduction to Information Technologies

B as ic D ef in it io n

•An integer is a number which has no fractional part. Examples:-2022 -213 0 1 514 323434565232

U n si g n ed B in ar y a n d B in ar y -C o d ed D ec im al B C D : B in ar y -C o d ed D ec im al

•Each decimal digit individually converted to binary Requires 4 bits per digit 8-bit location hold 2 BCD digits 00 to 99 68100110 1000BCD •Hexa: 4 bits can hold 16≠values, 0 to F •A to F not used in BCD

(2)

ITEC 1011Introduction to Information Technologies

R an g es f o r D at a F o rm at s

Etc.

09990999999016,777,21524

099099990 -65,53516

05119

0909902558

01277

0636

0315

090154

073

032

011

ASCIIBCDBinaryNo. of bits ITEC 1011Introduction to Information Technologies

In G en er al ( b in ar y )

2n -1

MaxMin 0n

Binary No. of bits Remember !! ITEC 1011Introduction to Information Technologies

S ig n ed I n te g er s

•Previous examples were for “unsigned integers”(positive values only!) •Must also have a mechanism to represent “signed integers”(positive and negative values!) •E.g., -510= ?2 •Two common schemes: 1) sign-magnitude 2) two’s complement ITEC 1011Introduction to Information Technologies

S ig n -M ag n it u d e

•Extra bit on left to represent sign 0 = positive value 1 = negative value •E.g., 6-bit sign-magnitude representation o +5 and –5: +5:000101 +5

-5:100101 -5

(3)

ITEC 1011Introduction to Information Technologies

R an g es ( re v is it ed )

Binary Etc.

31-316306

15-153105

7-71504

3-3703

1-1302

101

MaxMaxMinMin

Sign-magnitudeUnsigned No. of bits ITEC 1011Introduction to Information Technologies

In G en er al ( re v is it ed )

Binary 2n-1 -1-(2n-1 -1)2n -10n

MaxMaxMinMin

Sign-magnitudeUnsigned No. of bits ITEC 1011Introduction to Information Technologies

D if fi cu lt ie s w it h S ig n -M ag n it u d e

•Two representations of zero 0:000000 0:100000 •Arithmetic is awkward!

O n e’ s co m p le m en t

•Principle: Invert bits (01 and 10) 6:000110 -6:111001 •Range

(4)

A d d / S u b i n 1 ’s c o m p le m en t O v er fl o w

Overflow sign of result≠sign both operands ITEC 1011Introduction to Information Technologies

T w o ’s C o m p le m en t

Most common scheme of representing negative numbers in computers Affords natural arithmetic (no special rules!) To represent a negative number in 2’s complement notation 1.Decide upon the number of bits (n) 2.Find the binary representation of the positive value inn-bit 3.Flip all the bits (change 1’s to 0’s and vice versa) 4.Add 1 Learn!

(5)

T w o ’s c o m p le m en t re p re se n ta ti o n

ITEC 1011Introduction to Information Technologies

T w o ’s C o m p le m en t E x am p le

•Represent –5 in binary using 2’s complement notation 1.Decide on the number of bits, for example: 6 2.Find the binary representation of the positive (5) value in 6 bits 3.Flip all the bits 4.Add 1

111010 111010 +1 111011-5

000101 +5 ITEC 1011Introduction to Information Technologies

S ig n B it

•In 2’s complement notation, the MSB is the sign bit (as with sign-magnitude notation) 0 = positive value 1 = negative value -5:111011 -

+5:000101 +5? (previous slide) ITEC 1011Introduction to Information Technologies

“C o m p le m en ta ry ” N o ta ti o n

•Conversions between positive and negative numbers are easy •For binary (base 2)… +-

2’s C 2’s C

(6)

ITEC 1011Introduction to Information Technologies

E x am p le

+5 2’s C -5 2’s C +5

000101 111010 +1 111011 000100 +1 000101 ITEC 1011Introduction to Information Technologies

D et ai l fo r -2 0 1 1 1 0 1 1 0 0

-2010:PositiveValue = 00010100 “Flip”: 11101011 Add 1:+ 1 11101100

(One’s complement) ITEC 1011Introduction to Information Technologies

D et ai l fo r 1 1 0 0 0 1 1 - 2 9

2’s Complement:1100011 “Flip”:1011100 Add One:+1 1011101 Converts to:= -29 kc

(One’s complement) ITEC 1011Introduction to Information Technologies

R an g e fo r 2 ’s C o m p le m en t

•For example, 6-bit 2’s complement notatio -32-31...-101...31

000000111111000001011111100000100001 Negative, sign bit = 1Zero or positive, sign bit =

(7)

ITEC 1011Introduction to Information Technologies

R an g es ( re v is it ed )

63

31

15

7

3

1Max 000000

Min

Unsigned

Binary Etc.

31-3231-316

15-1615-155

7-87-74

3-43-33

1-21-12

1

MaxMaxMinMin

2’s complementSign-magnitudeNo. of bits ITEC 1011Introduction to Information Technologies

In G en er al ( re v is it ed )

2n -1

Max 0

Min

Unsigned

Binary 2n-1 -1-2n-1 2n-1 -1-(2n-1 -1)n

MaxMaxMinMin

2’s complemenSign-magnitudeNo. of bits To remember ITEC 1011Introduction to Information Technologies

2 ’s C o m p le m en t A d d it io n

•Easy •No special rules •Just add ITEC 1011Introduction to Information Technologies

W h at i s -5 p lu s + 5 ?

•Zero, of course, but let’s see -5:10000101 +5:+00000101 10001010

Sign-magnitude -5:11111011 +5:+00000101 00000000 Two’s-complement 11111111

(8)

ITEC 1011Introduction to Information Technologies

2 ’s C o m p le m en t S u b tr ac ti o n

•Easy •No special rules •Just subtract, well …actually …just add! AB=A+(-B) add2’s complement of B ITEC 1011Introduction to Information Technologies

W h at i s 1 0 s u b tr ac t 3 ?

•7, of course, but… •Let’s do it (we’ll use 6-bit values) 103=10+(-3)=7 001010 +111101 000111

+3:000011 1sC:111100 +1:1 -3:111101 ITEC 1011Introduction to Information Technologies

W h at i s 1 0 s u b tr ac t -3 ?

•13, of course, but… •Let’s do it (we’ll use 6-bit values) 10(-3)=10+(-(-3))=13 001010 +000011 001101

-3:111101 1sC:000010 +1:1 +3:000011

(-(-3))=3

O v er fl o w s an d C ar ri es

Références

Documents relatifs

Complement lysis assay comparing the resistance to lysis of Trypanosoma cruzi Colombiana strain wild-type (WT), transgenic pTEX, and pTEX– complement C2 receptor inhibitor

• misuse fixing and introducing (MFI) update: the CogniCrypt SAST analysis flags an issue with a usage at a given location in both apk j and apk j−1 , but the misuses are

Figure 1: Notation and interpretation for addition and subtraction tasks with integers.. this exemplary task provides evidence for our suc- cess in building up GVs for

The C5 convertase cleaves C5 into C5a (anaphylatoxin) and C5b which initiate the terminal pathway of the complement system, leading to the formation of the membrane attack

Host cells express complement regulatory molecules on their surface (membrane bound such as membrane cofactor protein, MCP, CD46 or complement receptor 1, CR1, CD35), or recruit

Dans une stru ture d'évaluation, les opérations des joueurs sont, par. dénition, monotones ( roissantes) dans tous

Les ruptures conventionnelles sont le troisième motif de sortie à tout âge mais sont moins fréquentes chez les salariés les plus jeunes (13 % des sorties pour les moins de 30 ans au

The Hindi negative parti- cles can be characterized in terms of the markedness they show at the level of sentence (or utterance): epistemic necessity is expressed mainly through