Number Systems for Students

Number Systems • • • • Decimal Binary Octal Hexadecimal Decimal (base 10) Binary (Base 2) Octal (Base 8) Hexadecim

Views 159 Downloads 10 File size 157KB

Report DMCA / Copyright

DOWNLOAD FILE

Recommend stories

Citation preview

Number Systems • • • •

Decimal Binary Octal Hexadecimal

Decimal (base 10)

Binary (Base 2)

Octal (Base 8)

Hexadecimal (Base 16)

00

0000

00

0

01

0001

01

1

02

0010

02

2

03

0011

03

3

04

0100

04

4

05

0101

05

5

06

0110

06

6

07

0111

07

7

08

1000

10

8

09

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

Conversion from base r to decimal

Decimal System • • • •

Radix or base 10 10 digits (0,1,2,…9) Coefficients are multiplied by powers of 10 Example:

Octal (base-8) to Decimal System • • • •

Radix or base 8 8 digits (0,1,2,3,4,5,6,7) Coefficients are multiplied by powers of 8 Example:

Hexadecimal (base-16) to decimal system • • • •

Radix or base 16 16 digits (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) Coefficients are multiplied by powers of 16 Example:

Binary (base-2) to decimal System • • • •

Radix or base 2 2 digits (0,1) Coefficients are multiplied by powers of 2 Example:

Examples: convert to decimal equivalent • (4021.2)5 =

(511.4)10

• (630.4)8 =

(408.5)10

• (B65F)16 =

(46687)10

Conversion from decimal to base r

Convert Decimal to Binary (Integer Part) Example: 50 (divide by 2)

(0110010)2

Convert Decimal to binary (Fraction Part) Example: 0.625 (multiply by 2)

(0.101)2

Convert Decimal to Binary (Integer and fraction ) Task: (41)10 to (bbbb)2 (101001)2 (0.6875)10 to (bbbb)2 (0.1011)2 (41.6875)10 to (bbbb)2 (101001.1011)2

(101001.1011) to (ddd)10

Octal and hexadecimal numbers

Convert from Decimal to Octal and back • Example: (120)10 to (ooo)8 (170)8 to (ddd)10

divide by 8 multiply by powers of 8

(0.521)10 to (ooo)8 mulitply by 8 (0.4126…)8 to (ddd)10 multiply by powers of 8

Convert from Decimal to Hexadecimal and back Example: (450)10 to (hhh)16 divide by 16 (1C2)16 to (ddd)10 multiply by powers of 16

(0.521)10 to (hhh)16 mulitply by 16 (0.8560…)16 to (ddd)10 multiply by powers of 16

Why octal and hexadecimal ?? • 23 = 8 and 24=16 • 3 digits required for octal • 4 digits required for hexadecimal (10 110 001 101 011.111 100 000 110)2=(26153.7406)8 2 6 1 5 3 7 4 0 6 (10 1100 0110 1011.1111 0000 0110)2=(2C6B.F06)16 2 C 6 B F 0 6

Why octal and hexadecimal ?? • Each octal digit converted to its 3 bit binary equivalent • Each hexadecimal digit converted to its 4 bit binary equivalent (673.124)8=(110 111 011.001 010 100)2 6 7 3 1 2 4 (306.D)16=(0011 0000 0110. 1101)2 3 0 6 D

Complements

Binary Numbers • An N-bit number a = aN-1 aN-2…..a2 a1 a0 maybe treated as signed or unsigned number. • Unsigned Number: All the N bits of an unsigned number are used to express the magnitude of the number.

Numbers

Signed-Magnitude • Designate left-most bit as a sign bit with no arithmetic weight 1-> negative, 0-> positive. • Easy to determine sign • Positive and negative zero (0000 vs. 1000) • Difficult to add numbers of different sign or subtract numbers of same sign (comparison) • N-1 bits are available to represent magnitude • Range of N-bit signed-magnitude number is: -(2N-1 –1) to (2N-1 –1)

Signed-Magnitude Advantages • – intuitive appeal & conceptual simplicity • – symmetric range • – simple negation Disadvantages • – fewer numbers encoded (two encodings for 0) • – subtraction is more complicated than in 2’scomp

2’s Complement Example: 2’s complement –ve number

2’s Complement • A specific case of radix complement • To negate or complement an N–digit number, subtract it from 2N. • If you then add the number and its complement, you get 2N. • If you only keep N-digits (discard final carry), you have zero.

2’s Complement • However, we need an extra bit to allow both positive and negative numbers. • 7 is 0111 • -7 is computed as 16-7=9 • 10000 - 0111 = 1001 = -7 • Add –7 and 7, discard carry, we get 0 • 0111 + 1001 = 1_0000

2’s Complement

2’s Complement

2’s Complement Example: 2’s complement –ve number

Example: Unsigned Number

2’s Complement Example of Equivalent Representation

2’s Complement 2’s Representation of 4-bit Numbers & Their Unsigned Equivalent Numbers

2’s Complements Representation Characteristics

• The representation of –ve No. facilitates the H/W implementation of many basic arithmetic operations • This representation is widely used for executing arithmetic operation in specified algorithms and general purpose architecture • In the example, the minimum +ve No. is 0 and maximum +ve No. is 7 • The min –ve No. is -8 • There is no equal opposite of -2N-1 in N bits 2’s complement representation

2’s Complements Method1 • we move from LSB to MSB leaving the first Non-Zero bit as it is and flipping all the rest of the bits. • This is certainly not the best way of taking 2’c complement in H/W • 2’s complement of 0010 is 1110

2’s Complements

Overflow overflow occurs when: • POS+POS=NEG or • NEG+NEG=POS

Addition/subtraction and Overflow • • • •

+3 0011 +4 0100 -------+7 0111

• -5 1011 • +6 0110 -------• +1 0001

+5 0101 +6 0110 -------+11 1011 -3 1101 -4 1100 --------7 1001

+5 0101 -6 1010 ---1 1111 -5 1011 -6 1010 -------11 0101

Multiplication (Unsigned) • Example: 0101 * 0011 (5 * 3)

2s Complement Sign Extension • Store 1101 (-3) in an 8 bit register • How to fix the problem?? • Example: 0101 * 0011 (5 * 3) • Answer = 1111 (is it 15 or -1??) • How to Fix the problem??