Chapter 1 (Lect1) - UAHhitedw/EE202/Lect1/Chapter1_1.pdf · Chapter 1 (Lect1) •Working with...

22
Chapter 1 (Lect1) Working with Binary, Octal, and Hexadecimal numbers Review Bases Conversions Addition and subtraction Number complements Signed and Unsigned representations (Base 2) Addition and Subtraction revisited (Base 2) Unsigned numbers Signed numbers

Transcript of Chapter 1 (Lect1) - UAHhitedw/EE202/Lect1/Chapter1_1.pdf · Chapter 1 (Lect1) •Working with...

Chapter 1 (Lect1)•Working with Binary, Octal, and Hexadecimal numbers

•Review•Bases•Conversions•Addition and subtraction

•Number complements•Signed and Unsigned representations (Base 2)•Addition and Subtraction revisited (Base 2)

•Unsigned numbers•Signed numbers

Base 10 Numbers

Number of discrete symbols: 10

Allowed values 0 to (Base – 1): 0 1 2 3 4 5 6 7 8 9

(542.75)10 = 500 + 40 + 2 + 0.7 + 0.05

= 5x102+4x101+2x100+7x10-1+5x10-2

Counting 0 – 9

Reset , increment 10 – 19

Reset , increment 20 – 29

… 99

Reset, Reset, increment

Base 2 – Binary numbers

2 –state Digital (electronic) numbering systemsNumber of discrete symbols: 2

Allowed values 0 to (Base – 1): 0 1

Counting

Base 10 Base 2

0

1

2

3

4

5

6

7

8

9

10

Base 8 – Octal numbersNumber of discrete symbols: 8

Allowed values 0 to (Base – 1): 0 1 2 3 4 5 6 7

Counting Base 10 Base 8

0

1

2

3

4

5

6

7

8

9

10

Base 16 – Hexadecimal numbersNumber of discrete symbols: 16

Allowed values 0 to (Base – 1): 0 1 2 3 4 5 6 7 8 9 A B C D E F

Counting Base 10 Base 16 Base 10 Base 16

0 11

1 12

2 13

3 14

4 15

5 16

6

7

8

9

10

Decimal Binary Octal Hexadecimal

0 0000 00 0

1 0001 01 1

2 0010 02 2

3 0011 03 3

4 0100 04 4

5 0101 05 5

6 0110 06 6

7 0111 07 7

8 1000 10 8

9 1001 11 9

10 1010 12 A

11 1011 13 B

12 1100 14 C

13 1101 15 D

14 1110 16 E

15 1111 17 F

Conversions ANY Base to Base 10

Write in the form:

ai x bi +… a2 x b2 + a1 x b1 + a0 x b0. a-1 x b-1 + a-2 x b-2 +… a-i x b-i

Where: “a” represents the coefficients

“b” is the base

Complete the sum, the answer will be in base 10.

Example 1

Conversions Base 10 to ANY Base

Example 2

(Decimal.dddd)10 (R4R3R2R1.w1w2w3)b

Binary (base 2) – primarily used in the areas of digital logic, communications,and signal processing.

Octal (base 8) – Mostly used in Computer applications-software providescondensed number notation.

Hexadecimal (base 16) – Mostly used in Computer applications-softwareprovides condensed number notation.

Binary numbers the length of the number can be quite large.

Can be shortened by using larger bases, that can be easily converted to binary.

This can be accomplished by using larger bases that are powers of 2 such as base 8 (23) and base 16 (24)

3 binary placeholders with 1 octal placeholder

4 binary placeholders with 1 hexadecimal placeholder

Base 2 to 81 0 1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 . 0 0 1 1 0

Base 2 to 161 0 1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 . 0 0 1 1 0

Base 8 to 2 123.4

Base 16 to 21F.3

Addition and Subtraction can be accomplish in any base by

applying the methods used in Base 10

Base 10

127 127+ 39 - 19

Base 2

1010 110+ 1111 - 11

Base 8

176 124+ 31 - 16

Digits of binary number 0 or 1 are referred to as bits

8 bits form a byte

210 = 1024 = K (kilo) 220 = 10242 = M (mega)

230 = 10243 = G (giga) 240 = 10244 = T (tera)

40 Mb = 40 x 220 = 40 x 1024 x 1024 bits = 41,943,040 bits

40,000,000 bits = 40,000,000/(1024 x 1024) = 38 Mb

40 MB = 40 x 220 bytes or 8 x 40 x 220 bits

(1001)2 = _______ bits (FFFF)16 = ______ bits

Number Complements

Useful at the hardware level to reduce the complexity of

subtraction and other logic operations

•For base “r” two types exist

•The radix or r’s complement

•The diminished radix or (r-1)’s complement

•So for base 2, r = 2

•The 2’s complement

•The 1’s complement

Formally: The 1’s complement is found from

(rn-1) – N

r = base, n = number of digits, N = the number

Informally: base 2.

flip all 0 to 1

flip all 1 to 0

The 1’s complement

Example 4

Example 3

Formally: The 2’s complement is found from

rn- N

r = base, n = number of digits, N = the number (not equal to zero), if N = 0,

then complement = 0. This is simply the 1’s complement + 1.

Informally: base 2.

Leave all least significant 0’s and the first least significant 1

alone, flip all 1 to 0, and 0 to 1 for the rest

For both 1’s and 2’s complements, if a radix point is present, remove

it, find the complement, put it back. The complement of the

complement = original number

The 2’s complement

Example 5

Example 6

Signed and Unsigned NumbersSigned-Magnitude Convention

Use left most bit of number: 0 = positive, 1 = negative

0111 = 7 1111 = -7

Must know if signed or unsigned type!!!

Signed-2’s Complement System

Include as extra left most bit

positive number the bit is 0, no complement taken,

negative number, take the complement of the entire number

including the sign bit

Example 7

Signed-Complement System (Base 2)

Note the extra bit 0_100 = 4Decimal Unsigned Signed

MagnitudeSigned‐2’s

Complement

4 100 0100 0100

3 011 0011 0011

2 010 0010 0010

1 001 0001 0001

0 000 0000 0000

‐0 ‐‐‐‐‐ 1000 ‐‐‐‐‐

‐1 ‐‐‐‐‐ 1001 1111

‐2 ‐‐‐‐‐ 1010 1110

‐3 ‐‐‐‐‐ 1011 1101

‐4 ‐‐‐‐‐ 1100 1100

To compute M-N, find the 2’s complement of N, then add it to MAssuming No Overflow

If The sum produces an end carryThrow it awayYour result is the solution

If The sum produces no end carryTake the 2’s complement of the result and add a negative signThe final result is in familiar notation

NOTE: The procedure is for the r’s complement, if using the (r-1)’s complement, when a carry occurs it must be added back to the result rather than discarded

Subtraction Using Signed-2’s Complement Addition

M N≥

M N<

Example 8

Signed Number Addition

Signed-2’s Complement: Add the numbers including the sign bit, if carry out occurs discard. If no carry out the answer is in signed-2’s complement form. Both cases assume no overflow, the remaining MSB is sign.

0101 = 1101= 1011= 0011=

Signed Number Subtraction

Signed-2’s complement form: given M – N, take the 2’s complement of N, including the sign bit and add the numbers. A carry out is discarded, your answer is in signed-2’s complement form can be positive or negative.

M = 1011 = N = 0010 =

What you should know

1. Be able to count in binary, octal, and hex.2. Be able to convert any base to base 2.3. Be able to convert a base 10 number to any base.4. Know the Signed-Magnitude and Signed-Complement

number representations.5. Be able to add and subtract base 2 numbers

a) Unsignedb) Signed-2’s complement form