Number System

59
GHT 205 Department of Geology, University of Dhaka SMK Number System A number system defines a set of values used to represent quantity . We talk about the number of people attending class, the number of modules taken per student, and also use numbers to represent grades achieved by students in tests. Stone Age: knots, some stone marks Roman Empire: more systematic notation devised a number system which could represent all the numbers from 1 to 1,000,000 using only seven symbols I = 1 ,V = 5 ,X = 10 ,L = 50 ,C = 100 ,D = 500 ,M = 1000 A small bar placed above a symbol indicates the number is multiplied by 1000. Concept of zero by Maya- I century, Hindu-V century Positional-value systems: decimal, binary, octal, etc..

Transcript of Number System

Page 1: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Number System A number system defines a set of values used to represent

quantity. We talk about the number of people attending class, the

number of modules taken per student, and also use numbers to

represent grades achieved by students in tests.

Stone Age: knots, some stone marks

Roman Empire: more systematic notation devised a number

system which could represent all the numbers from 1 to 1,000,000

using only seven symbols

•I = 1 ,V = 5 ,X = 10 ,L = 50 ,C = 100 ,D = 500 ,M = 1000

A small bar placed above a symbol indicates the number is

multiplied by 1000.

Concept of zero by

Maya- I century, Hindu-V century

Positional-value systems: decimal, binary, octal, etc..

Page 2: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Numbers

Natural Numbers Zero and any number obtained by repeatedly adding one to it.

Examples: 100, 0, 45645, 32

Negative Numbers A value less than 0, with a – sign

Examples: -24, -1, -45645, -32

Integers A natural number, a negative number, zero

Examples: 249, 0, - 45645, - 32

Rational Numbers An integer or the quotient of two integers

Examples: -249, -1, 0, ¼ , - ½

Page 3: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Number system No. of digits

1. Decimal : 10 (0,1,2,3,4,5,6,7,8,9)

2. Binary : 2 (0,1)

3. Octal : 8 (0,1,2,3,4,5,6,7)

4. Hexadecimal : 16 (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)

Number Systems

Page 4: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Decimal Numbers

• Decimal ea s that e ha e ten digits to use in our

representation (the symbols 0 through 9)

• Decimal number 4,536?

– it is four thousands plus five hundreds plus three tens

plus six ones.

• Decimal number: 329:

329

102 101 100

3x100 + 2x10 + 9x1 = 329

Page 5: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Page 6: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Binary Numbers

• Binary (base two) system:

– has two states: 0 and 1

• Basic unit of information is the binary digit, or bit.

• Binary number 101

101

22 21 20

1x4 + 0x2 + 1x1 = 5

most

significant

least

significant

Page 7: Number System

GHT 205 Department of Geology, University of Dhaka SMK

1 0 1 1 1 1 . 0 0 1

2 2 2 2 2 2 2 2 2

5 4 3 2 1 0 -1 -2 -3

We write: ( 1 0 1 1 1 1 . 0 0 1 )2

base point or radix

Digits are called bits

Base Weight

Page 8: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Binary Number System

• One bit has 2 possible states: 0, 1

• Two bits have 4 possible states:

B1 B0

0 0 0

1 0 1

2 1 0

3 1 1

2*2= 22 = 4

• n bits have 2n possible states

Page 9: Number System

GHT 205 Department of Geology, University of Dhaka SMK

• Three bits have 8 possible states

• Four bits have 16 possible states

B2 B1 B0

0 0 0 0

1 0 0 1

2 0 1 0

3 0 1 1

4 1 0 0

5 1 0 1

6 1 1 0

7 1 1 1

2*2*2= 23 = 8

Binary Number System B3 B2 B1 B0

0 0 0 0 0

1 0 0 0 1

2 0 0 1 0

3 0 1 0 0

4 1 0 0 0

5 1 0 0 1

6 1 0 1 0

7 1 1 0 0

8 0 0 1 1

9 0 1 1 0

10 0 1 0 1

11 1 1 1 0

12 1 1 0 1

13 1 0 1 1

14 0 1 1 1

15 1 1 1 1

2*2*2*2= 24 = 16

?

Page 10: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Octal Numbers

• O tal ea s that e ha e eight digits to use in our

representation (the symbols 0 through 7)

• In octal, instead of ten digits, we only have eight. So we

resort to changing the digits to the left more frequently.

0 1 2 3 4 5 6 7

10 11 12 13 14 15 16 17

20 21 22 23 24 25 26 27

Page 11: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Hexadecimal Numbers

• Hexade i al means that we have sixteen digits to use in

our representation (the symbols 0 to 9 and A,B,C,D,E,F)

• Hex number 27B?

2x256 + 7x16 + 11x1 = 635

27B

161 160 162

Page 12: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Hexadecimal

Decimal Octal

Binary

Number Conversion

The possibilities

Page 13: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Quick Example

2510 = 110012 = 318 = 1916

Base

Page 14: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Decimal to Binary

Hexadecimal

Decimal Octal

Binary

Page 15: Number System

GHT 205 Department of Geology, University of Dhaka SMK

• Technique

– Multiply each bit by 2n, where n is the weight of the bit

– The weight is the position of the bit, starting

from 0 on the right

– Add the results

Binary to Decimal Conversion

Page 16: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Convert to Decimal

1. 10011.110

2. 1110101.01

101011.012 => 1 x 20 = 1

1 x 21 = 2

0 x 22 = 0

1 x 23 = 8

0 x 24 = 0

1 x 25 = 32

0 x 2-1 = 0

1 x 2-2 = 0.25

43.2510

Examples

Page 17: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Decimal to Binary

Hexadecimal

Decimal Octal

Binary

Page 18: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Decimal to Binary Conversion

To convert a decimal to a binary number, use repetitive division.

• Divide the number by 2. Write the remainder as the least significant

digit (rightmost digit).

• The quotient becomes the dividend in the next stage. Continue to

divide by 2 until the quotient is zero, writing each remainder from right

to left.

Page 19: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Do it …

12510 = ?

2 2 125

62 1 2

31 0 2

15 1 2

7 1 2

3 1 2

1 1 2

0 1

12510 = 1111101

2

Page 20: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Binary to Octal

Hexadecimal

Decimal Octal

Binary

Page 21: Number System

GHT 205 Department of Geology, University of Dhaka SMK

• Technique

– Organize the stream of binary digits into groups of

three (starting on right)

– Convert to octal digits

To convert from base 2 to base 8

111100101

111 100 101

7 4 5

Page 22: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Co ert it…

10110101112 = ?8

1 011 010 111

1 3 2 7

10110101112 = 1327

8

Page 23: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Octal to Binary

Hexadecimal

Decimal Octal

Binary

Page 24: Number System

GHT 205 Department of Geology, University of Dhaka SMK

• Technique

– Convert each octal digit to a 3-bit equivalent

binary representation

3 5 7

011 101 111

357 base 8 is 011101111 base 2

Binary

Octal

Page 25: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Example

7058 = ?2

7 0 5

111 000 101

7058 = 111000101

2

Page 26: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Binary to Hexadecimal

Hexadecimal

Decimal Octal

Binary

Page 27: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Binary to Hexadecimal

• Technique

– Organize the stream of binary digits into

groups of four, starting on right

– Convert to hexadecimal digits

10010010111000011010

1001 0010 1110 0001 1010

9 2 E 1 A

Binary

Grouping Hexadecimal

Page 28: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Do it ….

10101110112 = ?

16

10 1011 1011

2 B B

10101110112 = 2BB

16

Page 29: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Hexadecimal to Binary

Hexadecimal

Decimal Octal

Binary

Page 30: Number System

GHT 205 Department of Geology, University of Dhaka SMK

• Technique

– Convert each hexadecimal digit to a 4-bit

equivalent binary representation.

9 2 E 1 A

1001 0010 1110 0001 1010

Page 31: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Do it …

10AF16 = ?

2

1 0 A F

0001 0000 1010 1111

10AF16 = 0001000010101111

2

Page 32: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Octal to Decimal

Hexadecimal

Decimal Octal

Binary

Page 33: Number System

GHT 205 Department of Geology, University of Dhaka SMK

• Technique

– Multiply each bit by 8n, where n is the eight of the bit

– The weight is the position of the bit, starting

from 0 on the right

– Add the results

1373

= 1×83+3×82+7×81+3×80

= 512+192+56+3

= 763

Page 34: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Do it …

7248 => 4 x 80 = 4

2 x 81 = 16

7 x 82 = 448

46810

Page 35: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Decimal to Octal

Hexadecimal

Decimal Octal

Binary

Page 36: Number System

GHT 205 Department of Geology, University of Dhaka SMK

• Technique

– Divide by 8

– Keep track of the remainder

123410 = ?

8

8 1234

154 2 8

19 2 8

2 3 8

0 2

123410 = 2322

8

Page 37: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Do it … Decimal to Octal

(154)10

154 ÷ 8 = 19 (Q) 2 (R)

19 ÷ 8 = 2 (Q) 3 (R)

2 ÷ 8 = 0 (Q) 2 (R)

Result: 232

763 ÷ 8 = 95 (Q) 3 (R)

95 ÷ 8 = 11 (Q) 7 (R)

11 ÷ 8 = 1 (Q) 3 (R)

1 ÷ 8 = 0 (Q) 1 (R)

Result: 1373

(763)10

Page 38: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Decimal to Hexadecimal

Hexadecimal

Decimal Octal

Binary

Page 39: Number System

GHT 205 Department of Geology, University of Dhaka SMK

• Technique

– Divide by 16

– Keep track of the remainder

(154)10

154 ÷ 16 = 9 (Q) 10 (R)

10 ÷ 16 = 0 (Q) 10 (R)

Result: AA

Page 40: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Do it …

123410 = ?

16

123410 = 4D2

16

16 1234

77 2 16

4 13 = D 16

0 4

Page 41: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Hexadecimal to Decimal

Hexadecimal

Decimal Octal

Binary

Page 42: Number System

GHT 205 Department of Geology, University of Dhaka SMK

• Technique

– Multiply each bit by 16n, where n is the

eight of the it – The weight is the position of the bit, starting

from 0 on the right

– Add the results

32FB

= 3×163+2×162+15×161+11×160

= 4096+512+240+11

= 4859

Page 43: Number System

GHT 205 Department of Geology, University of Dhaka SMK

ABC16 => C x 160 = 12 x 1 = 12

B x 161 = 11 x 16 = 176

A x 162 = 10 x 256 = 2560

274810

Do it …

Page 44: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Exercise – Convert ...

Decimal

Binary

Octal

Hexa-

decimal

33

1110101

703

1AF

Page 45: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Decimal

Binary

Octal

Hexa-

decimal

33 100001 41 21

117 1110101 165 75

451 111000011 703 1C3

431 110101111 657 1AF

Answer

Page 46: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Signed Magnitude

• In decimal we use a - in front of a number to indicate

negative.

• In binary we can use a leading bit to represent sign:

– 0: Positive

– 1: Negative

Example:

0 1101B = + (1*23 + 1*22 +0*21 +1*20) = 13D

1 1101B = - (1*23 + 1*22 +0*21 +1*20) = -13D

Binary Arithmetic

Page 47: Number System

GHT 205 Department of Geology, University of Dhaka SMK

A B A + B

0 0 0

0 1 1

1 0 1

1 1 10

Unsigned Addition

10010 10010 1111

+ 1001 + 1011 + 1

11011 11101 10000

10111

+ 111

carry

Page 48: Number System

GHT 205 Department of Geology, University of Dhaka SMK

• Two n-bit values

– Add individual bits

– Propagate carries

Techniques

1

1

1

1

0

0

0

0

0

0

1

1

1

0

1

0

1

0

1

0

0

1

0

1

1

1

0

0

1

1

0

0

---

---

---

---

---

---

---

---

---

---

---

---

0

01

01

10

11

10

10

01

10

01

01

00

Page 49: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Binary Subtraction

Techniques

If the lower (subtrahend) digit is greater than the upper

(minuend) digit, borrow from the next column to the left.

Subtract the lower value from the upper value 0 - 0 = 0

1 - 0 = 1

1 - 1 = 0

0 - 1 = 1, with a borrow of 1 from the next column

1

1 1 1 0 1(29)

- 1 0 1 1(11)

1 0 0 1 0(18)

Page 50: Number System

GHT 205 Department of Geology, University of Dhaka SMK

1100101001

- 110110110

101110011

11000

- 10011

00101

011

Practice

01111011

Page 51: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Binary Multiplication

A B A B

0 0 0

0 1 0

1 0 0

1 1 1

1110

x 1011

1110

1110

0000

1110

10011010

Page 52: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Complements

O e s Co ple e t : I ert

T o s Co ple e t : O e s Co ple e t + 1

Binary Number 1 1 1 1 0 0 0 0 1 1 1 1

O e s Co ple e t

T o s Co ple e t +

= 0 0 0 0 1 1 1 1 0 0 0 1

**Binary subtraction is performed by adding two’s complement

Page 53: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Positive one 0001 negative one 1111 (Two’s Complement) Positive two 0010 negative two 1110 (II)

Positive three 0011 negative three 1101 (II)

Positive four 0100 negative four 1100 (II)

Positive five 0101 negative five 1011 (II)

Positive six 0110 negative six 1010 (II) Positive seven 0111 negative seven 1001 (II)

T o s Co ple e t

00101 (5) 01001 (9)

+ 11011 (-5) +10111 (-9)

00000 (0) 00000 (0)

Page 54: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Practice

B – A = ?

Binary Value of A = 10001110 B= 11110000

01100010

Page 55: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Binary-coded decimal, or BCD, is a method of using binary digits to represent the

decimal digits 0 through 9. A decimal digit is represented by four binary digits, as

shown below:

The binary combinations 1010 to 1111 are invalid and are not used.

BCD

Page 56: Number System

GHT 205 Department of Geology, University of Dhaka SMK

In unpacked BCD, a decimal digit is stored in one byte and in

packed BCD, four bits are used to keep one digit, so two digits are

stored in one byte, one in the lower half and one in the upper half

of the byte.

BCD and binary are not the same.

For example, 4910

in binary is 1100012,

but 4910

in BCD is 01001001BCD

.

4 9

0100 1001 = 01001001BCD

(PACKED BCD)

Each decimal digit is converted to its binary equivalent.

UNPACKED & PACKED BCD

Page 57: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Conversion of decimal to BCD or BCD to decimal is similar to the conversion of hexadecimal to binary and vice versa.

For example, let's go through the conversion of 26410

to BCD.

Use the block format that we used in earlier conversions. First,

write out the decimal number to be converted; then, below each

digit write the BCD equivalent of that digit:

The BCD equivalent of 26410

is 001001100100BCD

BCD Conversion

Page 58: Number System

GHT 205 Department of Geology, University of Dhaka SMK

To convert from BCD to decimal, simply reverse the process as shown:

The DECIMAL equivalent of 100110000011BCD

is 98310

Page 59: Number System

GHT 205 Department of Geology, University of Dhaka SMK

Alpha Numeric Code : 8- bit codes, for characters and digits

American Standard Code for Information Interchange

Extended Binary-Coded Decimal Interchange Code

ASCII :

EBCDIC :