HEXADECIMAL NUMBERS Code

42
Introduction to Microprocessors Number Systems and Conversions No. 1-1 9/6/00 HEXADECIMAL NUMBERS Code WRITING one’s and zero’s can be error prone when dealing with large numbers. IBM came up with the following method of dealing with these numbers. BASE 16 with digits 0 - 15 in base 10 are represented by the following notation in Hexadecimal. 0 16 = 0000 2 = 0 10 8 16 = 1000 2 = 8 10 1 16 = 0001 2 = 1 10 9 16 = 1001 2 = 9 10 2 16 = 0010 2 = 2 10 A 16 = 1010 2 = 10 10 3 16 = 0011 2 = 3 10 B 16 = 1011 2 = 11 10 4 16 = 0100 2 = 4 10 C 16 = 1100 2 = 12 10 5 16 = 0101 2 = 5 10 D 16 = 1101 2 = 13 10 6 16 = 0110 2 = 6 10 E 16 = 1110 2 = 14 10 7 16 = 0111 2 = 7 10 F 16 = 1111 2 = 15 10

description

WRITING one’s and zero’s can be error prone when dealing with large numbers. IBM came up with the following method of dealing with these numbers. BASE 16 with digits 0 - 15 in base 10 are represented by the following notation in Hexadecimal. 0 16 = 0000 2 = 0 10 8 16 = 1000 2 = 8 10 - PowerPoint PPT Presentation

Transcript of HEXADECIMAL NUMBERS Code

Page 1: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-1 9/6/00

HEXADECIMAL NUMBERS

CodeWRITING one’s and zero’s can be error prone when dealing with large numbers. IBM came up with the following method of dealing with these numbers. BASE 16 with digits 0 - 15 in base 10 are represented by the following notation in Hexadecimal.

016 = 00002 = 010 816 = 10002 = 810

116 = 00012 = 110 916 = 10012 = 910

216 = 00102 = 210 A16 = 10102 = 1010

316 = 00112 = 310 B16 = 10112 = 1110

416 = 01002 = 410 C16 = 11002 = 1210

516 = 01012 = 510 D16 = 11012 = 1310

616 = 01102 = 610 E16 = 11102 = 1410

716 = 01112 = 710 F16 = 11112 = 1510

Page 2: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-2 9/6/00

Base 16 Conversion

EXAMPLE

Convert A716 to binaryNote: This is easy because of the relationship between the two bases

A = 1010 7 = 0111

Therefore 0A7H or $A7 = 10100111

Note leading 0 before A.Since this is a number a different base than base 10, absence of the zero may confuse a compiler. Therefore it is customary to add the leading 0 to any hex character that begins with a letter of the alphabet(A,B,C,D,E,F) !! These are NUMBERS in base 16 !!

Page 3: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-3 9/6/00

HEXADECIMAL TO DECIMAL

• Similar Rules as to those in binary to decimal– Convert to binary then weighted multiplication -OR-

– Leave in HEX and use HEX multiplication

• EXAMPLE (repeated multiplication)

$F8E6H = F(16)3 + 8 (16)2 + E(16)1 + 6(16)0

= 15(16)3 + 8 (16)2 + 14(16)1 + 6(16)0

= 61,440 + 2048 + 224 +6

= 63,718

Page 4: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-4 9/6/00

DECIMAL TO HEXADECIMAL

• Similar Rules as to those in decimal to binary Repeated HEX division

• EXAMPLE (repeated division)

• Divisors are for 16 binary digits (4 HEX)

247910 =

2479/16 = 154 remainder 15 or F

154/16 = 9 remainder 10 or A

9/16 = 9 remainder 9 or 9

Answer = 9AFH

Page 5: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-5 9/6/00

DECIMAL TO HEXADECIMAL

ALTERNATE

• Same EXAMPLE (but weighted division)

• Divisors are for 16 binary digits (4 HEX)

4096, 256, 16, 1

247910 =

2479/256 = 9 remainder .68359375 x256 =

175/16 = 10 or A remainder .9375 x 16 =

15/1 = 15 or F

Answer = 9AFH

Page 6: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-6 9/6/00

BINARY CODES

DECIMAL 8421 BINARY0 0000 0000

1 0001 0001

2 0010 0010

3 0011 0011

4 0100 0100

5 0101 0101

6 0110 0110

7 0111 0111

8 1000 1000

9 1001 1001

10 0001 0001 1010

11 0001 0010 1011

....

98 1001 1000 1100010

99 1001 1001 1100011

7421 6311 5421 5311 5211

0000 0000 0000 0000 0000

0001 0001 0001 0000 0001

0010 0011 0010 0011 0011

0011 0100 0011 0100 0101

0100 0101 0100 0101 0111

0101 0111 1000 1000 1000

0110 1000 1001 1001 1001

1000 1001 1010 1011 1011

1001 1011 1011 1100 1101

1010 1100 1100 1101 1111

4 Bit BCD CODESBCD

Page 7: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-7 9/6/00

MORE 4-BIT BCD CODES

Decimal 4221 3321 2421 84/2/1 74/2/1

0 0000 0000 0000 0000 0000

1 0001 0001 0001 0111 0111

2 0010 0010 0010 0110 0110

3 0011 0011 0011 0101 0101

4 1000 0101 0100 0100 0100

5 0111 1010 1011 1011 1010

6 1100 1100 1100 1010 1001

7 1101 1101 1101 1001 1000

8 1110 1110 1110 1000 1111

9 1111 1111 1111 1111 1110

The / is subtractweight

Page 8: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-8 9/6/00

5-BIT CODES

Decimal 2-out of-5 63210 Shift-Counter 86421 51111

0 00011 00110 00000 00000 00000

1 00101 00011 00001 00001 00001

2 00110 00101 00011 00010 00011

3 01001 01001 00111 00011 00111

4 01010 01010 01111 00100 10000

5 01100 01100 11111 00101 100006 10001 10001 11110 01000 11000

7 10010 10010 11100 01001 11100

8 10100 10100 11000 10000 11110

9 11000 11000 10000 10001 11111

Page 9: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-9 9/6/00

OTHER CODES

• Alphanumeric Codes– ASCII CODE 7 BITS

– EBCDIC CODE 8 BITS

– UNICODE 16 Bits

Page 10: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-10 9/6/00

ASCII CODEPart 1

b6b5b4 (column)

b3b2b1b0

Row(hex)

000 0

001 1

010 2

011 3

100 4

101 5

110 6

111 7

0000 0 NUL DLE SP 0 @ P ` p0001 1 SOH DC1 ! 1 A Q a q0010 2 STX DC2 " 2 B R b r0011 3 ETX DC3 # 3 C S c s0100 4 EOT DC4 $ 4 D T d t0101 5 ENQ NAK % 5 E U e u0110 6 ACK SYN & 6 F V f v0111 7 BEL ETB ' 7 G W g w1000 8 BS CAN ( 8 H X h x1001 9 HT EM ) 9 I Y I y1010 A LF SUB * : J Z j z1011 B VT ESC + ; K [ k {1100 C FF FS , < L / l |1101 D CR GS - = M ] m }1110 E SO RS . N ^ n ~1111 F SI US / ? O _ o DEL

Page 11: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-11 9/6/00

ASCII CODECONTROL CODES

NUL Null DLE Data link escapeSOH Start of heading DC1 Device control 1STX Start of text DC2 Device control 2ETX End of text DC3 Device control 3EOT End of transmission DC4 Device control 4ENQ Enquiry NAK Negative acknowledgeACK Acknowledge SYN SynchronizeBEL Bell ETC End transmitted blockBS Backspace CAN CancelHT Horizontal tab EM End of mediumLF Line feed SUB SubstituteVT Vertical tab ESC EscapeFF Form feed FS File separatorCR Carriage return GS Group separatorSO Shift out RS Record separatorSI Shift in US Unit separatorSP Space DEL Delete or rubout

Page 12: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-12 9/6/00

EBCDICPart I

Most Significant Hexadecimal DigitLeast SignificantDigit 0 1 2 3 4 5 6 7

0 Null Data link escape Digit select Space

& -

1 Start of heading Device control 1Start ofsignificance

/

2 Start of text Device control 2 Field separatorSynchronizationcharacter

3 End of text Tape mark 4 Punch off Restore Bypass PN 5 Horizontal tab New line Line feed Record separator

6 Lowercase BackspaceEnd oftransmission block

Uppercase

7 Delete Idle EscapeEnd oftransmission

8 Cancel 9 RLF End of medium \

AStart of manualmessage

Cursor control Set mode

centsign

! | :

B Vertical tab Customer use 1 Customer use 2 Customer use 3 . $ , #

C Form feedInterchange fileseparator

Device control 4 < * % @

D Carriage returnInterchange groupseparator

EnquiryNegativeacknowledgment

( ) _ '

E Shift outInterchange recordseparator

Acknowledge + ; > =

F Shift inInterchange unitseparator

BellStart of specialsequence

| or[

]or]

? "

Page 13: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-13 9/6/00

EBCDICPART II

LeastSignificant

Most Significant Hexadecimal Digit

Digit 8 9 A B C D E F0 { } ` 01 a j A J 12 b k s B K S 23 c l t C L T 34 d m u D M U 45 e n v E N V 56 f o w F O W 67 g p x G P X 78 h q y H Q Y 89 i r z I R Z 9A B C D E F

Page 14: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-14 9/6/00

UNICODE

16 BIT CODE

First Page 0000H - 00FFH Same as ASCII

Has not been standardized the remaining

0FFFFH minus 00FFH available for all remaining

countries and languages!

Page 15: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-15 9/6/00

Number Systems

Representation of Negative Numbers

Three major schemes:

sign and magnitude

ones complement

twos complement

nines complement

tens complement

Assumptions:

we'll assume a 4 bit machine word

16 different values can be represented

roughly half are positive, half are negative

Page 16: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-16 9/6/00

Number SystemsSign and Magnitude Representation

0000

0111

0011

1011

11111110

1101

1100

1010

1001

1000

0110

0101

0100

0010

0001

+0+1

+2

+3

+4

+5

+6

+7-0

-1

-2

-3

-4

-5

-6

-7

0 100 = + 4 1 100 = - 4

+

-

High order bit is sign: 0 = positive (or zero), 1 = negative

Three low order bits is the magnitude: 0 (000) thru 7 (111)

Number range for n bits = +/-2 -1

Representations for 0 Two +/-

n-1

Page 17: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-17 9/6/00

Number SystemsOnes Complement

Subtraction implemented by addition & 1's complement

Still two representations of 0! This causes some problems

Some complexities in addition

0000

0111

0011

1011

11111110

1101

1100

1010

1001

1000

0110

0101

0100

0010

0001

+0+1

+2

+3

+4

+5

+6

+7-7

-6

-5

-4

-3

-2

-1

-0

0 100 = + 4 1 011 = - 4

+

-

Page 18: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-18 9/6/00

Number RepresentationsTwos Complement

0000

0111

0011

1011

11111110

1101

1100

1010

1001

1000

0110

0101

0100

0010

0001

+0+1

+2

+3

+4

+5

+6

+7-8

-7

-6

-5

-4

-3

-2

-1

0 100 = + 4 1 100 = - 4

+

-

Only one representation for 0

One more negative number than positive number

like 1's compexcept shiftedone positionclockwise

Page 19: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-19 9/6/00

BINARY ARITHMETIC

RULES FOR ADDITION

0 + 0 = 0

0 + 1 = 1

1 + 0 = 1

1 + 1 = 0 + carry 1 to next column

RULES FOR SUBTRACTION

0 - 0 = 0

0 - 1 = 1 and borrow from next column

1 - 0 = 1

1 - 1 = 0

Borrowing 1 from next column is equivalent to subtracting 1 from that column

Page 20: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-20 9/6/00

Addition

EXAMPLE

ADD 1010 to 1101

1010

+ 1101

10111

SUBTRACT 1010 from 1101

borrow 4 subtract 2

1101 nothing in 4 position

- 1010

0011

Page 21: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-21 9/6/00

Number Representations

Addition and Subtraction of NumbersSign and Magnitude

4

+ 3

7

0100

0011

0111

-4

+ (-3)

-7

1100

1011

1111

When signs is same,result sign bit is thesame as the operands'sign. Just add magnitudes

4

- 3

1

0100

1011

0001

-4

+ 3

-1

1100

0011

1001

When signs differ,operation is subtract,sign of result dependson sign of number withthe larger magnitude. Thisis what we do in base 10.

Page 22: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-22 9/6/00

Number Systems

Sign and Magnitude

Cumbersome addition/subtraction.

Must compare magnitudes to determine the sign of result.

Page 23: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-23 9/6/00

Ones Complement

The general formula for finding

/N = (2n - 1) - N

To find 1's complement of 7

2 = 10000

-1 = 00001

1111

-7 = 0111

1000 = -7 in 1's comp.

4

The symbol N, with a bar over it, is used to represent the complement. Also used to indicate inversion are /, ‘, or ! (CUPL and ABEL)

N is positive number, then N is its negative 1's complement. N is the precision, as many 1’s as required. Binary can be any precision, but BCD requires 4 bits.

Precision 4 bitsTherefore,

Page 24: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-24 9/6/00

Ones Complement

ZERO

Applying the general formula/N = (2n - 1) - N

To find 1's complement of 0

2 = 10000

-1 = 00001

1111

-0 = 0000

1111 = -0 in 1's comp.

4

NOTE:

The complement of 0 is 1111, which means, there are2 representations of 0.

0000 Positive 0

1111 Negative 0

Page 25: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-25 9/6/00

SHORTCUT1’s Complement

Shortcut method:

Replace all 0’s with 1’s, and all 1’s with 0’s

simply compute bit wise complement

7 in 1’s complement 0111 -> 1000

Page 26: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-26 9/6/00

Number SystemsAddition and Subtraction of Numbers

Ones Complement Calculations

4

+ 3

7

0100

0011

0111

-4

+ (-3)

-7

1011

1100

10111

1

1000

4

- 3

1

0100

1100

10000

1

0001

-4

+ 3

-1

1011

0011

1110

End around carry

End around carry

Page 27: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-27 9/6/00

Number SystemsAddition and Subtraction of Binary Numbers

Ones Complement Calculations

Why does end-around carry work?

Its equivalent to subtracting 2 and adding 1n

M - N = M + / N = M + (2n - N -1) = (M - N) + 2n - 1

For (M > N)

-M + (-N) = M + N = (2n - M - 1) + (2n - N - 1)

= 2n + [2n - 1 - (M + N)] - 1

For M + N < 2n-1

after end around carry the -1 is canceled if a carry, else not:

= 2n - 1 - (M + N)

this is the correct form for representing -(M + N) in 1's complement!

Page 28: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-28 9/6/00

Number SystemsTwo’s Complement Numbers

/N = 2n - N

Note: subtract number immediately.

Example: Twos complement of 7

Example: Twos complement of 0

Only 4bits can represent number.The most significant 1 is dropped!

42 = 10000

7 = 0111

1001 = represents -7

sub

2 = 10000

-0 = 0000

0000 = 0

4

sub

Shortcut method Number 1:

Twos complement =1’s complement + 1

0111 -> 1000 + 1 -> 1001 (representation of -7)

1001 -> 0110 + 1 -> 0111 (representation of 7)

Page 29: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-29 9/6/00

SHORTCUT

Shortcut method Number 2:

Starting from the right, least significant bit, if 0 leave unchanged.Continue from right to left, if 0, no change. When the first 1 is encountered,we leave it unchanged, but complement each digit to the left.

710 = 01112 Apply method 10012 = -710 .

6810 = 011001002 yields 100111002 . The lead 0 is important so that the number to be converted is positive! In base 10, the - sign

does that for us. With only on and off (0,1) we need this extra bit

of information to describe the signed number.

-6810 = 10011100 yields 011001002 = + 6810

Page 30: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-30 9/6/00

Number SystemsAddition and Subtraction of Binary Numbers

Twos Complement Calculations

4

+ 3

7

0100

0011

0111

-4

+ (-3)

-7

1100

1101

11001

4

- 3

1

0100

1101

10001

-4

+ 3

-1

1100

0011

1111

Simpler addition scheme makes twos complement the most commonchoice for integer number systems within digital systems

Page 31: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-31 9/6/00

Number SystemsAddition and Subtraction of Binary Numbers

Twos Complement Calculations

Why can the carry-out be ignored?

-M + N when N > M:

M* + N = (2 - M) + N = 2 + (N - M)n n

Ignoring carry-out is just like subtracting 2n

-M + -N where N + M < or = 2 n-1

-M + (-N) = M* + N* = (2 - M) + (2 - N)

= 2 - (M + N) + 2n n

After ignoring the carry, this is just the right twos compl.representation for -(M + N)!

n n

Page 32: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-32 9/6/00

Number SystemsOverflow Conditions

Add two positive numbers to get a negative number

or two negative numbers to get a positive number

5 0101+3 0011-8 1000

-7 - 2 = +7

0000

0001

0010

0011

1000

0101

0110

0100

1001

1010

1011

1100

1101

0111

1110

1111

+0

+1

+2

+3

+4

+5

+6

+7-8

-7

-6

-5

-4

-3

-2

-1

0000

0001

0010

0011

1000

0101

0110

0100

1001

1010

1011

1100

1101

0111

1110

1111

+0

+1

+2

+3

+4

+5

+6

+7-8

-7

-6

-5

-4

-3

-2

-1

4 bit representation3 bits + sign in msbrange -8 to +7

+1=6 (ok)

+2=7 (ok)+3=-8 (error)

Page 33: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-33 9/6/00

OVERFLOW

If carry-in (penultimate) is added to sign bit and there is a carry-outthen no overflow.

if carry-in differs fromcarry-out then overflow

This is true for both 1’s and 2’s complement addition.

Page 34: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-34 9/6/00

Number SystemsOverflow Conditions

Example is using 2’s Complement

5

3

-8

0 1 1 1 carry 0 1 0 1

0 0 1 1

1 0 0 0

-7

-2

7

1 0 0 0 carry 1 0 0 1

1 1 1 0

1 0 1 1 1

Note: the carry and penultimate carry are not the same!This can be very easily implemented in hardware. XOR

Overflow

5

2

7

0 0 0 0 carry 0 1 0 1

0 0 1 0

0 1 1 1

-3

-5

-8

1 1 1 1 carry 1 1 0 1

1 0 1 1

1 1 0 0 0

No overflow No overflow

Overflow when carry in to sign does not equal carry out

Overflow

Page 35: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-35 9/6/00

BCD AdditionBCD Number Representation

Decimal digits 0 thru 9 represented as 0000 thru 1001 in binary

Addition:

5 = 0101

3 = 0011

1000 = 8

5 = 0101

8 = 1000

1101 = 13!

Problemwhen digit

sum exceeds 9

Solution: add 6 (0110) if sum exceeds 9.

5 = 0101

8 = 1000

1101

6 = 0110

1 0011 = 1 3 in BCD

9 = 1001

7 = 0111

1 0000 = 16 in binary

6 = 0110

1 0110 = 1 6 in BCD

Page 36: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-36 9/6/00

BCD Subtractin

Must use 10’s complement

To find 10’s complement, first generate 9’s complement by subtractingThe number from 9.

If n = 9, 9-9 =0 9’s complement of 9 is 0 or 0000If n = 8, 9-8 =1 9’s complement of 8 is 1 or 0001If n = 7, 9-7 =2 9’s complement of 7 is 2 or 0010If n = 6, 9-6 =3 9’s complement of 6 is 3 or 0011If n = 5, 9-5 =4 9’s complement of 5 is 4 or 0100If n = 4, 9-4 =5 9’s complement of 4 is 5 or 0101If n = 3, 9-3 =6 9’s complement of 3 is 6 or 0110If n = 2, 9-2 =7 9’s complement of 2 is 7 or 0111If n = 1, 9-1 =8 9’s complement of 1 is 8 or 1000If n = 0, 9-0 =9 9’s complement of 0 is 9 or 1001

Add 1 to 9’s complement to find 10’s complement.

Page 37: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-37 9/6/00

Example of BCD Subtract

To subtract 2 from 5, find 10’s complement of 2 which is 10002 4 BitRepresentation.

5 5 0101-2 8 1000

3 1 3 1101 The 1 carry, is normal form and indicates answer is 3. In binary, 1001 is exceeded! Must add 6 to correct.

Known as BCD adjust. 0110 1 0011 The 1 carry is normal form answer is 3 base 10.

Page 38: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-38 9/6/00

Addition Examples

4 BITS signed andunsigned

Decimal BinaryUnsigned

1’sComplement

2’sComplement

9’sComplement

10’sComplement

9’sComplementBinaryCodedDecimal

10’sComplementBinaryCodedDecimal

No Sign No Sign 4 BitSigned

NoOverflow

4 BitSigned

NoOverflow

Base10

SignedNo

Overflow

Base10

SignedNo

Overflow

Base2

Signed NoOverflow4 Bit BCD

Base2

Signed NoOverflow4 Bit BCD

1+3

4

00010011

0 0 11

0100

00010011

0 0 1 1

0100

00010011

0 0 1 1

0100

1+3

4

1+3

4

00010011

0 0 1 1

0100

00010011

0 0 1 1

0100

4 BitNo Sign

NoOverflow

4 BitSigned

Overflow

4 BitSigned

Overflow

Base10

SignedOverflow

Base10

SignedOverflow

Base2 9’sSigned

Overflow4 Bit BCD

Base2 10’sSigned

Overflow4 Bit BCD

5+7

12

01010111

0 1 1 1

1100

01010111

0 1 1 1

1100

01010111

0 1 1 1

1100

05+07

12

5+7

12

01010111

0 1 1 1

1100

01010111

0 1 1 1

1100

Page 39: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-39 9/6/00

Addition Examples

4 BITS signed andunsignedDecimal Binary

Unsigned1’sComplement

2’sComplement

9’sComplement

10’sComplement

9’sComplementBinaryCodedDecimal

10’sComplementBinaryCodedDecimal

No Sign No Sign 4 BitSigned

NoOverflow

4 BitSigned

NoOverflow

Base10

SignedNo

Overflow

Base10

SignedNo

Overflow

Base2

Signed NoOverflow4 Bit BCD

Base2

Signed NoOverflow4 Bit BCD

7-2

5

01111101

1 1 1 1

01001

0101

01111110

1 1 1 1

0101

797

1 1

041

05

798

1 1

05

01111101

1 1 1 1

01001

0101

01111110

1 1 1 1

0101

4 BitSigned

NoOverflow

4 BitSigned

NoOverflow

Base10

SignedNo

Overflow

Base10

SignedNo

Overflow

Base2 9’sSigned

NoOverflow4 Bit BCD

Base2 10’sSigned

NoOverflow4 Bit BCD

5-7

-2

01011000

0 0 0 0

11010

1101 (-2) 0010

01011001

0 0 0 1

1110

00011

(-2) 0010

0592

97

-2

593

98

011

(-2) 02

01011000

0 0 0 0

11010

1101 (-2) 0010

01011001

0 0 0 1

1110

00011

(-2) 0010

Page 40: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-40 9/6/00

Excess 3 Code

Excess-3 code is another important BCD Code.

To encode a decimal number, add 3 to each digit before converting to binary.

EXAMPLE (Note: 2 digits represented by 2 4 bit numbers)

12 to excess-3 = 1+3=4 2+3=5

4 5

0100 0101

29 to excess-3 = 2+3=5 9+3=12

5 12

0101 1100

Page 41: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-41 9/6/00

EXAMPLES OF EXCESS ADDITION

In excess-3 addition, whenever we add two numbers whose sum is 9 or less, an excess-6 number is formed. To return to excess-3 we must subtract 3.

EXAMPLE

2 +5 = 7

0101 2

1000 5

1101 excess-6

- 0011

1010 excess-3 equivalent of 7

CASE 1

Page 42: HEXADECIMAL NUMBERS Code

Introduction to MicroprocessorsNumber Systems and Conversions

No. 1-42 9/6/00

EXAMPLES OF EXCESS ADDITION

In excess-3 addition, whenever we add two numbers whose sum is greater than 9, there will be a carry from one group to the next. When this happens, the group that produced the carry will revert to 8421 (BCD). To return to excess-3 we must subtract 3 from that group.

EXAMPLE 0 1 carry not carried to 10’s because of sum

29 0101 1100 excess-3 for 29

+ 39 0110 1100 excess-3 for 39

68 1100 1000 first result

- 0011 + 0011 subtract less than 9, add 3

1001 1011 excess-3 for 68

CASE 2