Assoc. Prof. Dr. Ahmet Turan ÖZCERİT. The base of numbers Conversion between number bases ...

Preview:

Citation preview

Introduction to Computer Engineering

WEEK-4

Number Systems

Assoc. Prof. Dr. Ahmet Turan ÖZCERİT

2

The base of numbers

Conversion between number bases

Arithmetic operations on different bases

Number Systems

You will learn:

The Base of Numbers

He/She can define the term of number bases

3

Computers use a number base other than base-10, namely binary

Each data used and stored in computer represented in binary numbers

Binary numbers are not easy to do arithmetic operations, so we use hex

and octal numbers for the sake of simplicity

All characters, images, audio and video samples are also presented in

binary numbers

The General Term of Number Systems

He/She can define the term of number bases

4

N: Digit value

d: Number digit

R: Number radix(base)

N=dnRn+ dn-1Rn-1 + …+ d2R2 + d1R1+d0R0 (for integers)

N=dnRn+dn-1Rn-1+…+d1R1+d0R0 , d1R-1+ d2R-2 +…+ dnR-n (for real numbers)

The number of digits in the R-based number system is R, the largest digit

is R-1, and the least digit is 0.

The largest number for n-digit is Rn-1 and the number of different value

for n-digit is Rn

Binary NumbersHe/She can make operation on binary numbers

5

The largest digit in binary system R-1 => 2-1 => 1

The least digit in binary system is 0

Each radix in binary number systems is called BIT (BInary DigiT).

The most significant bit (MSB)

The binary number general form:

B= dn2n + dn-12n-1 +…….+ d222 + d121 + d020 , d12-1 +d22-2 +dn2-n

Binary System Decimal System

00 0

01 1

10 2

11 3

Binary Numbers

He/She can make operation on binary numbers

6

What is binary value of following binary number: 1 0110 1101

B= 1*28 +0*27+1*26 + 1*25 + 0*24 + 1*23 + 1*22 + 0*21 + 1*20

B= 256 + 0 + 64 + 32 + 0 + 8 + 4 + 0 + 1

B= 36510

What is binary value of following binary number: 1 0110 1101, 1101

B= 1*28 +0*27+1*26+1*25+0*24+1*23+1*22+0*21+1*20, 1*2-1+1*2-2+0*2-

3+1*2-4

B= 256 + 0 + 64 + 32 + 0 + 8 + 4 + 0 + 1 + 0.5 +0.25 + 0+ 0.0625

B= 365,812510

Octal Numbers

He/She can make operation on octal numbers

7

Octal numbers are used to present binary numbers with 3-digit format

The digits used in Octal Systems: 0, 1, 2, 3, 4, 5, 6, 7

O= dn8n + dn-18n-1 +…….+ d282 + d181 + d080 , d18-1 +d28-2 +dn8-n

Binary Octal

000 0

001 1

010 2

011 3

100 4

101 5

110 6

111 7

Hexadecimal Numbers

He/She can make operation on hex numbers

8

Hex numbers are used to present binary numbers with 4-digit format

The digits used in Octal Systems: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

O= dn16n + dn-116n-1 +…….+ d2162 + d1161 + d0160 , d116-1 +d216-2 +dn16-n

Binary Hex

0000 0

0001 1

0010 2

0011 3

0100 4

0101 5

0110 6

0111 7

Binary Hex

1000 8

1001 9

1010 A

1011 B

1100 C

1101 D

1110 E

1111 F

Decimal to Binary Conversion

He/She can convert number bases each other

9

The steps of converting of 117,8610 decimal number into a binary number

First, the integer part of the number is resolved then real partDivision Remainde

rResult

117/2 =58 1 B0=1

58/2 = 29

0 B1=0

29/2 =14 1 B2=1

14/2 =7 0 B3=0

7/2 =3 1 B4=1

3/2 =1

1 B5=1

1/2 =0 1 B6=1

Multiply Integer Result

0.86*2=1.72 1 b1=1

0.72*2=1.44 1 b2=1

0.44*2=0.88 0 b3=0

0.88*2=1.76 1 b4=1

0.76*2=1.52 1 b5=1

0.52*2=1.04 1 b6=1

0.04*2=0.08 0 b7=0

(117,86)10 = (1110101,1101110….)2

Decimal to Octal Conversion

He/She can convert number bases each other

10

Convert a real decimal number (0,513)10 into an octal number

Operation Multiply Integer Result

0.513*8 4.104 4 o0=1

0.104*8 0.832 0 o1=0

0.832*8 6.656 6 o2=6

0.656*8 5.248 5 o3=5

0.248*8 1.984 1 o4=1

(0,513)10 ≅ (0,40651)8

Decimal to Hex Conversion

He/She can convert number bases each other

11

Convert a decimal number (214)10 into a hex numberOperation Division Remainder Result

214/16 13 6 O0=6

13/16 0 13 O1=D (214)10 = (D6)16

Convert a decimal number (423)10 into a hex numberOperation Division Remainder Result

423/16 26 7 O0=7

26/16 1 10 O1=A

1 1 O2=1 (423)10 = (1A7)16

Binary to Decimal Conversion

He/She can convert number bases each other

12

Convert a binary number (100.01)2 into a decimal number

100.01= 1*22 + 0*21 + 0*20 , 0*2-1 + 1*2-2

= 1*4 + 0 + 0 , 0 + 1* ¼

= 4 + 0 +0 , 0+ 0.25

= (4,25)10

Binary to Octal Conversion

He/She can convert number bases each other

13

Converting a binary number (110111011.1100111)2 into an octal number

For integer part; start from just after the dot towards to the leftmost digit and combine 3-bits as a group. Fill zeros if the group is less than 3-bit

1 5 6 6.

For real part; start from just after the dot towards to the rightmost digit and

combine 3-bits as a group. Fill zeros if the group is less than 3-bit

.6 3 4

1 1 0 1 1 1 0 1 1 0 .

. 1 1 0 0 1 1 1

Binary to Hex Conversion

He/She can convert number bases each other

14

Converting a binary number (110111011.1100111)2 into a hex number

For integer part; start from just after the dot towards to the leftmost digit and combine 4-bit as a group. Fill zeros if the group is less than 4-bit

3 7 6.

For real part; start from just after the dot towards to the rightmost digit and

combine 4-bit as a group. Fill zeros if the group is less than 4-bit

.C E

1 1 0 1 1 1 0 1 1 0 .

. 1 1 0 0 1 1 1

Octal to Binary and Decimal

He/She can convert number bases each other

15

Converting an Octal number into a binary numberConvert each digit into its 3-bit binary counterpart.

Example(673.124)8 =(110 111 011. 001 010 100)2

Converting an octal number into a decimal numberMultiply each digit’s value by radix and sum all terms

Example(372.2)8 = 3x82 + 7x81 + 2x80 + 2x8-1

= 3x64 + 7x8 + 2x1 +2x0.125=(250.25)10

Octal to Hex Conversion

He/She can convert number bases each other

16

Converting an Octal number into a hex numberStep1. Convert each digit into its 3-bit binary counterpart.Step2. Compose 4-bit groupsStep3. Convert 4-bit into hex counterpart

Integer part group direction . Real part group direction

Example(5431)8 = ( ? )16

Step1. (101 100 011 001)2

Step2. 1011 0001 1001

Step3. B 1 9 (5431)8 = (B19)16

Hex to Binary, Decimal Conversion

He/She can convert number bases each other

17

Converting an hex number into a binary numberConvert each digit into its 4-bit binary counterpart.

Example(673.124)16 =(0110 0111 0011. 0001 0010 0100)2

Converting an hex number into a decimal numberMultiply each digit’s value by radix and sum all terms

Example(372)16 = 3x162 + 7x161 + 2x160

= 3x256+ 7x16 + 2x1= 768 + 112 + 1= (881)10

Hex to Octal Conversion

He/She can convert number bases each other

18

Converting an Hex number into a Octal numberStep1. Convert each digit into its 4-bit binary counterpart.Step2. Compose 3-bit groupsStep3. Convert 3-bit into octal counterpart

Integer part group direction . Real part group direction

Example(E0CA)16 = ( ? )8

Step1. (1110 0000 1100 1010)2

Step2. (001 110 000 011 001 010)2

Step3. ( 1 6 0 3 1 2)8

(E0CA)16 = (160312)8

Binary Addition

He/She can do arithmetic operations on various radix

19

0+0 =0

1+0 =1

1+1 =0 Carry=1

1 1 1 1

1 0 1 0

0 1 1 0

0 0 1 1

1 0 0 1 0

Carry

Carry

Carry

Carry

Carry

Binary Subtraction

He/She can do arithmetic operations on various radix

20

0-0 =0

1-0 =1

1-1 =0

0-1 =1 borrow=1

1 0 0 1

1 1 1

0 0 1 0

Binary Subtraction by r complement

He/She can do arithmetic operations on various radix

21

In digital electronics, it is easier to create adder than subtractor unit.

M-N can be redefined as M+( r complement of N)

N can be negated by 1’s complement but 1’s complement contain

both +0 and -0.

STEP-1:

Convert subtraction operation into addition by using r complement

STEP-2:

a. If an extra carry is obtained at the end, discard it and

the number is assumed as positive.

b. If no carry is obtained, apply r complement to result and add 1

Binary Subtraction by 2’s complement

He/She can do arithmetic operations on various radix

22

Example with extra carry:

N can also be negated by 2’s complement (1’s complement+1)

M=1010100, N=1000100 M-N=?

M-N = M+(-N)

= M+ (2’s complement of N)

= M+ (1’s complement+1)

1’s Complement of N= (0111011)2

2s complement of N (1’s complement of N + 1) = (0111100)2

1010100

0111100

1 0010000 MSB is discarded, the result= (0010000)2

Binary Subtraction by 2’s complement

He/She can do arithmetic operations on various radix

23

Example without extra carry:

M=10001002 (68)10

N =10101002 (84)10

M-N =? for 2’s complement

1’s complement of N= (0101011)

2’s complement of N (1’s complement of N + 1) = (0101100)

1000100

0101100

1110000 No carry (-16)10

1s comp 0001111

0000001

-(0010000)2 (-16)10

Binary Multiplication

He/She can do arithmetic operations on various radix

24

1101 13

0101 5

1101 65 0000 1101

100001

Binary Division110010 101

101 1010

00101 101

0000

QUESTIONS

He/She can do arithmetic operations on various radix

25

?

Recommended