1 of 58

Number Systems And Code Systems

DJM 30073

DIGITAL SYSTEM

​

​

​

2 of 58

Chapter Objectives

  • Review the decimal number system
  • Count in the binary number system
  • Convert from decimal to binary and from binary to decimal
  • Convert from Octal number to binary and decimal and vice versa
  • Convert hexadecimal number to binary and decimal and vice versa
  • Determine the 2’s compliments in addition and subtraction operations.
  • BCD 8421 codes
  • Convert BCD 8421 codes to binary and vice versa
  • Convert data to ASCII code using the ASCII code table
  • ….and More

​

3 of 58

Introduction

  • The binary system and digital codes are fundamental to computers and to digital electronic in general.
  • The binary number system such as decimal, hexadecimal and octal is presented.
  • Arithmetic operations with binary numbers are covered to provide a basis for understanding how computers and many other types of digital systems work.

4 of 58

4

NUMBER SYSTEM

DECIMAL NUMBER

(Base 10)

BINARY NUMBER

(Base 2)

OCTAL NUMBER

(Base 8)

HEXADECIMAL NUMBER

(Base 16)

5 of 58

Number System

  • 0 ~ 9

​

  • 0 ~ 1

​

  • 0 ~ 7

​

  • 0 ~ F
  • Decimal

​

  • Binary

​

  • Octal

​

  • Hexadecimal

6 of 58

DECIMAL NUMBER

  • Symbol : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Also called base 10 system or radix of 10
  • e.g. 1210 subscript 10 shows that

number 12 is in base 10.

  • Commonly used by human

6

7 of 58

DECIMAL NUMBER SYSTEM

  •  

8 of 58

Decimal Numbers

  • In decimal number system each of the ten digits, 0 through 9

Example:

Express the decimal number 2745.214 as a sum of the values of each digit

9 of 58

BINARY NUMBER

  • Symbol : 0 and 1
  • Also called base 2 system
  • Commonly used by computer
  • Each binary digit is called a bit

where n is the no of bits used (2n)

  • e.g. 10102

9

MSB

(most significant bit)

LSB

(least significant bit)

to show

base 2

0 0 0 0 0

1 0 0 0 1

2 0 0 1 0

3 0 0 1 1

4 0 1 0 0

5 0 1 0 1

6 0 1 1 0

7 0 1 1 1

8 1 0 0 0

9 1 0 0 1

10 1 0 1 0

11 1 0 1 1

12 1 1 0 0

13 1 1 0 1

14 1 1 1 0

15 1 1 1 1

Decimal Number

Binary Number

10 of 58

BINARY NUMBER SYSTEM

  • The binary number system is another way to represent quantities.
  • It is less complicated than the decimal system because it has only two digits.
  • The binary system with its two digits is a base two system
  • The two binary digits (bits) are 1 and 0.

​

11 of 58

Binary Numbers

  • The binary number system is another way to represent quantities. There are 1 (HIGH) and 0 (LOW)
  • The binary numbering system has a base of 2 with each position weighted by a factor of 2:

12 of 58

Binary Digits

  • The conventional numbering system uses ten digits: 0,1,2,3,4,5,6,7,8, and 9.

​

  • The binary numbering system uses just two digits: 0 and 1.
  • The two binary digits are designated 0 and 1

​

  • They can also be called LOW and HIGH, where LOW = 0 and HIGH = 1

13 of 58

13

23= 8

MSB

22 = 4

​

21 = 2

​

20 = 1

LSB

Decimal Equivalent

0

0

0

0

0

0

0

0

0

0

1

1

0

1

0

1

0

1

2

3

0

0

0

0

1

1

1

1

0

0

1

1

0

1

0

1

4

5

6

7

1

1

1

1

0

0

0

0

0

0

1

1

0

1

0

1

8

9

10

11

1

1

1

1

1

1

1

1

0

0

1

1

0

1

0

1

12

13

14

15

Binary Counting Sequence.

Weights

14 of 58

Convert binary numbers to decimal numbers and vice versa

Binary Decimal

110112 = 1 x 24 + 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 = 2710

1101.012 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 + 0 x 2-1 + 1 x 2-2 = 13.2510

15 of 58

Example

Convert the binary whole number 1101101 to decimal

Solution:

Weight: 26 25 24 23 22 21 20

Binary : 1 1 0 1 1 0 1

1101101 = 26 + 25 + 23 + 22 + 20

= 64 + 32 + 8 + 4 + 1 = 109

Try This:

​

1111001

16 of 58

16

Decimal Binary

2 methods : i) reverse process (binary )

ii) repeated division by 2 , 8 , 16

17 of 58

Sum-of-Weight Method

The decimal number 9, for example, can be expressed as the sum of binary weight of:

1 0 0 1

Example:

Convert the following decimal numbers to binary:

a) 12 b) 25 c) 58 d) 82

1100 11001 111010 1010010

18 of 58

18

ii) 2510 = 110012

  1. 4510 = 32 + 8 + 4 + 1 = 25 + 0 + 23 + 22 + 0 + 20

1 0 1 1 0 12

Reverse Process.

Repeated Division by 2

LSB(least significant bit)

MSB (most significant bit)

Remainder form the binary

25 / 2 = 12.5

0.5 x 2 = 1

19 of 58

19

iii) 0.312510 = 0.01012

LSB

MSB

Stop when fractional part is all zeros

0.312510 x 2 = 0.625

0.625 x 2 = 1.25

0.25 x 2 = 0.50

0.50 x 2 = 1.00

​

0

1

1

0

0.0 1 0 12

20 of 58

Decimal Number

Binary Number

0

0

0

0

0

1

0

0

0

1

2

0

0

1

0

3

0

0

1

1

4

0

1

0

0

5

0

1

0

1

6

0

1

1

0

7

0

1

1

1

8

1

0

0

0

9

1

0

0

1

10

1

0

1

0

11

1

0

1

1

12

1

1

0

0

13

1

1

0

1

14

1

1

1

0

15

1

1

1

1

22 21 20

0 0 0

0 0 1

0 2 0

0 2 1

4 0 0

4 0 1

4 2 0

4 2 1

23 22 21 20

8 0 0 0

8 0 0 1

8 0 2 0

8 0 2 1

8 4 0 0

8 4 0 1

8 4 2 0

8 4 2 1

21 of 58

An Application

22 of 58

OCTAL NUMBER

  • The octal number system provides a convenient way to express binary numbers and codes.
  • The octal number system is composed of eight digit, which are 0,1,2,3,4,5,6,7
  • Counting in octal is similar to counting in decimal, except that the digits 8 and 9 are not used.

​

23 of 58

OCTAL NUMBER

  • Symbol : 0, 1, 2, 3,4, 5, 6, 7
  • Also called base 8 system
  • Used in computer and micro processing application to simplify binary representation
  • Method of grouping binary number in groups of 3(example 111=7)
  • e.g. 128

subscript 8 shows that number 12 is in base 8.

​

​

23

0 1 2 3 4 5 6 7 8 9 10 11 12 13 1415

0 1 2 3 4 5 6 7 10 1112 13 14 15 16 17

Decimal

Octal

to show base 8

24 of 58

conversion of octal to binary numbers and vice versa

24

24

Octal Binary

Convert each octal digit to its 3-bit binary equivalent

4728 = 1001110102

624.58 = 110010100.1012

25 of 58

25

25

Binary Octal

110101102 = 3268

26 of 58

Conversion of octal to decimal numbers and vice versa

26

26

Octal Decimal

3728 = 3 x 82 + 7 x 81 + 2 x 80 = 25010

24.68 = 2 x 81 + 4 x 80 + 6 x 8-1 = 20.7510

27 of 58

28 of 58

Hexadecimal Numbers

  • Most digital systems deal with groups of bits in even powers of 2 such as 8, 16, 32, and 64 bits.
  • Hexadecimal uses groups of 4 bits.
  • Base 16
    • 16 possible symbols
    • 0-9 and A-F
  • Allows for convenient handling of long binary strings.

29 of 58

HEXADECIMAL NUMBER

  • Symbol : 0, 1, 2, 3,4, 5, 6, 7, 8, 9, A, B, C, D, E, F
  • Also called base 16 system
  • Used in computer and micro processing application to simplify binary representation
  • Method of grouping binary number in groups of 4(1111=F)
  • e.g. A716

​

29

Value of 10

Hexadecimal

0 1 2 3 4 5 6 7 8 9 10 11 12 13 1415

0 1 2 3 4 5 6 7 8 9 A B C D E F

Decimal

to show base 16

30 of 58

Hexadecimal Numbers

  • Convert from hex to decimal by multiplying each hex digit by its positional weight.

Example:

​

​

31 of 58

Conversion of hexadecimal to binary numbers and vice versa

31

35616 = 3 x 162 + 5 x 161 + 6 x 160 = 85410

Hexadecimal Decimal

2AF16 = 2 x 162 + 10 x 161 + 15 x 160 = 68710

32 of 58

Decimal Hexadecimal

32

42310 = 1A716

Remainders form the hexadecimal

204.12510 = CC.216

33 of 58

Hexadecimal Numbers

  • Convert from decimal to hex by using the repeated division method used for decimal to binary and decimal to octal conversion.
  • Divide the decimal number by 16
  • The first remainder is the LSB and the last is the MSB.
    • Note, when done on a calculator a decimal remainder can be multiplied by 16 to get the result. If the remainder is greater than 9, the letters A through F are used.

34 of 58

Hexadecimal Numbers

​

  • Example of hex to binary conversion:

35 of 58

Hexadecimal Numbers

36 of 58

Hexadecimal Numbers

  • Hexadecimal is useful for representing long strings of bits.
  • Understanding the conversion process and memorizing the 4 bit patterns for each hexadecimal digit will prove valuable later.

37 of 58

38 of 58

ARITHMETIC OPERATION

a) Addition

A 11101100

B + 1100110

101010010

​

b) Subtraction

A 101

B - 011

010

38

Right Column:

1 – 1 = 0

Middle Column:

Borrow 1 from next column to the left, making a 10 in this column, then 10-1=1

Left Column:

When a 1 is borrowed, a 0 is left, so 0-0=0

39 of 58

1’s and 2’s Complements of Binary Numbers

  • The 1’s and 2’s Complements of Binary Numbers are very important because they permit the representation of negative numbers.
  • The method of 2’s compliment arithmetic is commonly used in computers to handle negative numbers

40 of 58

Finding the 1’s Complement

The 1’s complement of a binary number is found by changing all 1s to 0s and all 0s to 1s.

Example:

1 0 1 1 0 0 1 0 (Binary Number)

0 1 0 0 1 1 0 1 (1’s Complement)

NOT Gate

41 of 58

Finding the 2’s Complement

The 2’s complement of a binary number is found by adding 1 to the LSB of the 1’s complement

Find the 2’s complement of 10110010

10110010 (Binary number)

+ 01001101 (1’s complement)

1 (Add 1)

01001110

42 of 58

� COMPLEMENT OF BINARY NUMBERS

​

  • 1’s complement of a binary number is found by changing all 1s to 0s and all 0s to 1s

​

​

  • 2,s complement is found by adding 1 to the LSB of the 1’s complement

or

leave all LSB ‘0’s and the first ‘1’ unchanged and replaced 1’s with 0’s and the 0’s with 1’s in all

​

​

​

42

43 of 58

44 of 58

ARITHMETIC OPERATIONS USING NUMBER SYSTEMS

ADDITION

SUBTRACTION

  • To subtract two signed numbers, take the 2s compliment of the subtrahend and add, discarding any final carry bit.

​

Example: Perform each the following subtractions of the sign numbers

(a) 00001000 – 00000011 (b) 00001100 – 11110111

(c) 11100111 - 00010011 (d) 10001000 – 11100010

​

Solution:

(a) 8 – 3 = 8 + (-3) = 5 00001000 minuend (+8)

+ 11111101 2’s of subtrahend (-3)

100000101 Difference (+5)

44

Discard Carry

45 of 58

(b) 12-(-9) = 12+9=21

00001100 minuend (+12)

+ 00001001 2’s of subtrahend (+9)

00010101 Difference (+21)

(c) -25-(+19) = -25+(-9)=-44

11100111 minuend (-25)

+ 11101101 2’s of subtrahend (-19)

111010100 Difference (-44)

(d) -120-(-30) = -120+30=-90

10001000 minuend (-120)

+ 00011110 2’s of subtrahend (+30)

10100110 Difference (-90)

​

​

Exercise : Subtract 01000111 from 01011000

45

Discard Carry

46 of 58

convert BCD 8421 codes to binary number and vise versa

Example: convert each decimal numbers to BCD

​

(a) 35 (b) 98 (c) 170 (d) 2469

​

Solution:

​

(a) 3 5 ( decimal )

0011 0101 ( BCD)

​

(b) 9 8

​

1001 1000

46

47 of 58

Example: convert each BCD to decimal numbers

​

(a) 10000110 (b) 00110101000

(c) 1001010001110000

Solution:

(a) 1000 0110

​

8 6

(b) 0001 1010 1000 1 10 8

* BCD code does not use (10 is invalid codes)

​

(c) 1001 0100 0111 0000

9 4 7 0

47

48 of 58

BCD

  • Binary Coded Decimal (BCD) is another way to present decimal numbers in binary form.
  • BCD is widely used and combines features of both decimal and binary systems.
  • Each digit is converted to a binary equivalent.

49 of 58

BCD

  • To convert the number 87410 to BCD:

​

8 7 4

0100 0111 0100 = 010001110100BCD

  • Each decimal digit is represented using 4 bits.
  • Each 4-bit group CAN NEVER BE GREATER THAN 9.
  • Reverse the process to convert BCD to decimal.

50 of 58

BCD

  • BCD is not a number system.
  • BCD is a decimal number with each digit encoded to its binary equivalent.
  • A BCD number is not the same as a straight binary number.
  • The primary advantage of BCD is the relative ease of converting to and from decimal.

51 of 58

BCD 8421 CODES

Decimal

5421

5311

4221

3321

2421

8421

7421

0

0000

0000

0000

0000

0000

0000

0000

1

0001

0001

0001

0001

0001

0001

0001

2

0010

0011

0010

0010

0010

0010

0010

3

0011

0100

0011

0011

0011

0011

0011

4

0100

0101

1000

0101

0100

0100

0100

5

1000

1000

0111

1010

1011

0101

0101

6

1001

1001

1100

1100

1100

0110

0110

7

1010

1011

1101

1101

1101

0111

1000

8

1011

1100

1110

1110

1110

1000

1001

9

1100

1101

1111

1111

1111

1001

1010

52 of 58

Alphanumeric Codes

  • Represents characters and functions found on a computer keyboard.
  • ASCII – American Standard Code for Information Interchange.
    • Seven bit code: 27 = 128 possible code groups
    • Table 2-4 lists the standard ASCII codes
    • Examples of use are: to transfer information between computers, between computers and printers, and for internal storage.

53 of 58

NUMBER CODES ACSII

  • Most widely used ACSII code
  • American Standard Code for Information Interchange
  • Pronounced "askee"
  • Consists seven-bit code i.e. 27 = 128 possible code groups (characters)
  • ASCII code is used for the transfer of alphanumeric information between a computer and external devices such as printer or another computer
  • A computer also uses ASCII internally to store the information that an operator types in at the computer’s keyboard.

53

54 of 58

ASCII CODE TABLE

MSB

LSB

 

Binary

 

000

 

001

 

010

 

011

 

100

 

101

 

110

 

111

 

Binary

 

Hex

 

0

 

1

 

2

 

3

 

4

 

5

 

6

 

7

0000

0

Nul

Del

sp

0

@

P

 

p

0001

1

Soh

Dc1

1

1

A

Q

a

q

0010

2

Stx

Dc2

“

2

B

R

b

r

0011

3

Etx

Dc3

#

3

C

S

c

s

0100

4

Eot

Dc4

$

4

D

T

d

t

0101

5

End

Nak

%

5

E

U

e

u

0110

6

Ack

Syn

&

6

F

V

f

v

0111

7

Bel

Etb

‘

7

G

W

g

w

1000

8

Bs

Can

(

8

H

X

h

x

1001

9

HT

Em

)

9

I

Y

i

y

1010

A

LF

Sub

.

:

J

Z

j

z

1011

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

 

55 of 58

Example:

The following is a message encoded in ASCII code.

What is the message?

1001000 1000101 1001100 1010000

​

Solution:

  • Convert each 7-bit code to its Hexadecimal equivalent.
  • The results are : 48 45 4C 50
  • Now, locate these Hexadecimal values in table ASCII and determine the character represented by each. The results are:

H E L P

​

56 of 58

TRY THIS

a) 54 4F 4C 4F 4E 47

​

b) 48 45 4C 4C 4F

c) 41 50 41 4B 48 41 42 41 52

​

d) GO TO 25

57 of 58

58 of 58

Thank You

“ Buku yang selalu dibaca tidak akan mengumpul habuk dan debu. Berjinaklah dengan buku kerana ia adalah teman yang paling berguna menimba ilmu “