0% found this document useful (0 votes)
171 views36 pages

Basic Digital Electronics - Unit 2

The document provides information about number systems and codes. It discusses binary, octal, hexadecimal, and binary-coded decimal (BCD) number systems. It covers how to convert between decimal, binary, octal, and hexadecimal numbers. It also discusses signed binary numbers and how to perform arithmetic operations like addition and subtraction using 1's and 2's complement representations in binary. The goal is for students to understand different number systems and be able to convert between them, as well as perform basic arithmetic operations on signed binary numbers.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
171 views36 pages

Basic Digital Electronics - Unit 2

The document provides information about number systems and codes. It discusses binary, octal, hexadecimal, and binary-coded decimal (BCD) number systems. It covers how to convert between decimal, binary, octal, and hexadecimal numbers. It also discusses signed binary numbers and how to perform arithmetic operations like addition and subtraction using 1's and 2's complement representations in binary. The goal is for students to understand different number systems and be able to convert between them, as well as perform basic arithmetic operations on signed binary numbers.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

2

NUMBER SYSTEMS AND CODES

At the end of the lesson, students should be able to:


Count in the binary number system. Convert from the decimal form to binary form and from binary form to decimal form including fractions. 3. Add and subtract binary numbers including fractions. 4. Determine ls and 2s compliments of a binary number. 5. Express signed numbers in binary form. 6. Carry out arithmetic operations with signed binary numbers. 7. Convert between the binary and octal number systems. 8. Convert between the binary and hexadecimal number system. 9. Express decimal numbers in binary coded decimal (BCD). 10. Add BCD numbers. 1. 2.

1. Understand the Gray and ASCII code is used.


UNIT 2: NUMBER SYSTEMS AND CODES

2.1

COUNT IN BINARY NUMBER SYSTEM

Only have 2 digits 0 and 1 (known as bits) It is expressed as a base of 2. Weight Binary Number 24 1
MSB

23 0

22 1

21 0

20 0

2-1 1

2-2 0

2-3 1

2-4 0
LSB

2.2

BINARY AND DECIMAL FORM TO BINARY FORM

CONVERT FROM DECIMAL TO BINARY FORM It use repeated division-by-2 Example: Convert 1210 to binary form.

Solution:
2 2 2 2 2 12 6 3 1 0 1210 = 11002
Check: Weight Binary Number
23 1

Remain 0 0 1 1 1210 = 1 1 0 0
2

From below

22 1

21 0

20 0

= 23 + 22 = 8 + 4 = 12

Fatma Syazana Zaini, IKM Besut, 2010

14

UNIT 2: NUMBER SYSTEMS AND CODES

CONVERT DECIMAL TO BINARY FORM INCLUDING FRACTION Fractional binary numbers are expressed as negative powers of 2. Multiply the decimal numbers by 2 repeatedly until the fraction become 0 or at the place you want. Example 1: Convert 0.312510 to binary form.

Solution:
Carry 0.3125 2 0.625 0.25 0.5 2 2 2 = 0.625 = 1.25 = 0.50 = 1.00
Stop until the fraction become 0.

=0.0101

0 1 0 1

Example 2: Convert 0.634210 to binary form.

Solution:
Carry 0.6342 0.2684 0.5368 0.0736 2 2 2 2 = 1.2684 = 0.5368 = 1.0736 = 0.1472
Stop at the place you want

= . 1010

1 0 1 0

Fatma Syazana Zaini, IKM Besut, 2010

15

UNIT 2: NUMBER SYSTEMS AND CODES

CONVERT FROM BINARY FORM TO DECIMAL POINT Multiply each bit by positional weight and add the weight of all bits that are 1 Discard the weight of all bits that are 0 Example: Express 11011012 to decimal form.

Solution:
Weight Binary Number 26 1 25 1 24 0 23 1 22 1 21 0 20 1

11011012 = 26 + 25 + 23 + 22 + 21 = 64 + 32 + 8 + 4 + 1 = 109

CONVERT FROM BINARY FORM TO DECIMAL FORM INCLUDING FRACTION Example: 1. Convert 0.1011 to decimal point.

Solution:
Weight Binary Number 0.10112 20 0. 2-1 1 2-2 0 2-3 1 2-4 1

= (0 20) + (1 2-1) + (0 2-2) + (1 2-3) + (1 2-4) = (0 0) + (1 1/2) + (0 1/4) + (1 1/8) + (1 1/16) = 0.5 + 0.125 + 0.0625

= 0.6875

Fatma Syazana Zaini, IKM Besut, 2010

16

UNIT 2: NUMBER SYSTEMS AND CODES

2. Convert 0.11001 to decimal point.

Solution:
Weight Binary Number 0.110012 20 0. 2-1 1 2-2 1 2-3 0 2-4 0 2-5 1

= 2-1 + 2-2 + 2-5 = 0.5 + 0.25 + 0.03125 = 0.78125

2.3

ADD AND SUBTRACT BINARY NUMBER INCLUDING

ADD BINARY NUMBER Basic rules: Carry 0+0=0 0+1=1 1+0=1 1+1=0 1 + 1 + (carry) = 1 0 0 0 1 1

Example: 1. Add 1012 to 102.

Check:
1 + 1 0 1 1 1 0 1

5 + 2 7

Fatma Syazana Zaini, IKM Besut, 2010

17

UNIT 2: NUMBER SYSTEMS AND CODES

2. Add 10102 to 112.


1

1 + 1

0 1

1 1 0

0 1 1

Check: 10 + 3 13

3. Add 11012 to 1102.


1

1 + 1 0

1 1 0

0 1 1

1 0 1

Check: 13 + 6 19

SUBTRACT BINARY NUMBER Case 1: 1 1 1 1 0 0 0 0 1 0 1

Check: 13 4 9

Case 2:

Check:
1 10 1 1 0 0 0 1 0 1

9 4 5

When borrowing 1 from left, it becomes 10. 10 1 = 1 (2 - 1 = 1)

Fatma Syazana Zaini, IKM Besut, 2010

18

UNIT 2: NUMBER SYSTEMS AND CODES

Case 3:

1 is borrowed from this column leaving 0 When 1 is borrowed from left, it becomes 1 When 1 is borrowed from left, it becomes 102. 102 12 = 12 1 0 = 0 without borrow

1 -

0 0 1

0 1 0

0 0 1

10 1 1

1 0 1

Check: 33 10 23

2.4

1S AND 2S COMPLEMENTS OF BINARY NUMBER

1s and 2s compliment of binary numbers are important because they permit the representation of negative (-ve) numbers. 1S COMPLEMENTS The 1s compliment of a binary is found by changing all 1s to 0s and all 0s to 1s. In other words, change each bits in the number to its complement. Example: Find the 1s complement of 11012. Solution: 1 1 0 1

0 0 1 0 11012 = 00102

Fatma Syazana Zaini, IKM Besut, 2010

19

UNIT 2: NUMBER SYSTEMS AND CODES

2S COMPLEMENTS The 2s complement of a binary number is formed by taking the 1s complement of the number and adding 1 to the least significant bit (LSB) position. Example 1: Find the 2s complement of 11012.

Solution:
1 0 + 0 0 1 1 0 0 1 1 0 1 1 2s complement Binary number 1s complement

Example 2: Find the 2s complement of 10011012.

Solution:
1 0 + 0 1 1 0 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 Binary number 1s complement Add 1 2s complement

Fatma Syazana Zaini, IKM Besut, 2010

20

UNIT 2: NUMBER SYSTEMS AND CODES

2.5

EXPRESS SIGNED NUMBERS IN BINARY FORM

THE SIGNED BITS The left most bit in a signed binary number is the sign bit, which tells you whether the number is positive or negative. A 0 sign bit indicates a positive number, and a 1 sign bit indicates a negative number.

SIGN MAGNITUDE FORM When a signed binary number is represented in sign magnitude, the left most bits is the sign bit and the remaining bits are the magnitude bits. The magnitude bits are in true (un-complemented) binary for both positive and negative numbers. For example, the decimal number +25 is expressed as an 8 bit signed number using the sign magnitude form as: 0 0 0 1 1 0 0 12
Sign bit Magnitude bit

The decimal number 25 is expressed as 1 0 0 1 1 0 0 12

REMEMBER:
The MSB is the sign bit, which tells us weather the number is positive or negative. Sign bit 0 Sign bit 1 = = positive negative

Fatma Syazana Zaini, IKM Besut, 2010

21

UNIT 2: NUMBER SYSTEMS AND CODES

1S COMPLEMENT Example: Using 8 bits, express decimal number +25 in 1s compliment. +25 : 0001 1001 1110 0110 binary number 1s complement

In 1s complement form, a negative number is the 1s complement of the corresponding positive number.
(dalam bentuk 1s C, nombor negative adalah 1s C untuk nombor positif)

2S COMPLEMENT Negative number is the 2s complement of the corresponding positive number. Example: Express decimal number -25 as 2s complement.

0 1 + 1

0 1 1

0 1 1

1 0 0

1 0 0

0 1 1

0 1 1

1 0 1 1

Binary number of +25 1s complement Add 1 2s complement

In the 2s complement form, a negative number is the 2s complement of the corresponding positive number.

Fatma Syazana Zaini, IKM Besut, 2010

22

UNIT 2: NUMBER SYSTEMS AND CODES

Example: Express the decimal number -39 as an 8 bit number in the sign-magnitude, 1s complement and 2s complement forms. + 39 = 0010 01112 In the sign-magnitude form -39 = 1010 01112 In 1s complement form -39 :0 0 1 0 1 1 0 1 0 1 1 1 1 0 0 0
Binary number (+39) 1s complement

In 2s complementform -39 :0 0 1 0 1 1 0 1 + 1 1 0 1 0 1 1 1 1 0 0 0 1 1 0 0 1
Binary number (+39) 1s complement Add 1 2s complement (-39)

2.6

ARITHMETIC OPERATIONS WITH SIGNED NUMBERS

ADDITION IN 2S COMPLEMENT SYSTEM o Case 1 : Two positive numbers The addition of +7 and +4 0 0 0 0 0 1 1 1 + 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1
(+ 7) (+ 4) (+ 11)

If the sum is positive, therefore, in true binary

Fatma Syazana Zaini, IKM Besut, 2010

23

UNIT 2: NUMBER SYSTEMS AND CODES

Case 2 :

Negative number < Positive number The addition of +15 and -6


To get -6, change +6 to 2s Complement

0 0 0 0 1 1 1 1 + 1 1 1 1

0 1 1 0 1 0 0 1 1 1 0 1 0

Binary number (+6) 1s complement Add 1 2s complement (-6)

0 0 0 0 1 1 1 1 + 1 1 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1

(+ 15) (- 6) (+ 9)

If there is a final carry bit, then discard. The sum is positive.

Case 3 :

Positive number < Negative number The addition of +16 and -24 0 0 0 1 1 1 1 0 + 1 1 1 0 1 0 0 0 0 1 1 1 1 1 0 0 0
Binary number (+24) 1s complement Add 1 2s complement (-24)

0 0 0 1 0 0 0 0 + 1 1 1 0 1 0 0 0 1 1 1 1 1 0 0 0

(+ 16) (- 24) (- 8)

Fatma Syazana Zaini, IKM Besut, 2010

24

UNIT 2: NUMBER SYSTEMS AND CODES

Case 4 :

Two negative number The addition of -5 and -9 - 5 :0 0 0 0 1 1 1 1 + 1 1 1 1 0 1 0 1 (+5) 1 0 1 0 1 1 0 1 1 (-5) + 1 1 1 1 -9 :0 0 0 0 1 1 1 1 1 0 0 1 (+9) 0 1 1 0 1 0 1 1 1 (-9)

1 1 1 1 1 0 1 1 + 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 0

(- 5) (- 9) ( - 14)

The final carry bit is discarded. The sum is negative.

Case 5 :- Equal and opposite number The addition of -9 and +9


1 1 1 1 1 1 1

1 1 1 0 1 1 1 1 + 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0

- 9 (in 2s complement form) + 9 0

The final carry bit is discarded.

Fatma Syazana Zaini, IKM Besut, 2010

25

UNIT 2: NUMBER SYSTEMS AND CODES

SUBTRACTION IN 2S COMPLEMENT SYSTEM Procedure: i. ii. iii. Negate the subtrahend will change the subtrahend to its equivalent value of opposite sign. Add the negation to the minuend the result will represent the difference between the subtrahend and minuend. Discarded any final carry bit.

Example: Perform each of the following subtractions of the signed numbers: a) +8 (+3) = 5 b) 12 (-9) = 21 c) -25 (+19) = -44 d) -120 (-30) = -90

Solutions:
a) +8 (+3) = 5
1 1 1 1

b) 12 (-9) = 21
1

0 0 0 0 1 0 0 0 + 1 1 1 1 1 1 0 1 1 0 0 0 0 0 1 0 1

0 0 0 0 1 1 0 0 + 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1

c) -25 (+19) = -44


1 1 1 1 1 1

d) -120 (-30) = -90


1 1

1 1 1 0 0 1 1 1 + 1 1 1 0 1 1 0 1 1 1 1 0 1 0 1 0 0
Fatma Syazana Zaini, IKM Besut, 2010

1 0 0 0 1 0 0 0 + 0 0 0 1 1 1 1 0 1 0 1 0 0 1 1 0

26

UNIT 2: NUMBER SYSTEMS AND CODES

2.7

OCTAL NUMBERING SYSTEM

Octal number system provides a convenient way to express binary numbers and code. However, it is used less frequently than hexadecimal in conjunction with computers and microprocessor to express binary quantities for input and output purposes.

OCTAL TO BINARY CONVERSION Octal digit is represented by a 3-bit binary number.


OCTAL DIGIT 0 1 2 3 4 5 6 7 Table 1 BINARY 000 001 010 011 100 101 110 111

Example: Convert each of the following octal numbers to binary. a) 138 Solution: a) 1 0 0 1 3 0 1 1 0 1 0 258 = 010 1012 b) 2 5 1 0 1 b) 258 c) 1408 d) 72568

138 = 001 0112

Fatma Syazana Zaini, IKM Besut, 2010

27

UNIT 2: NUMBER SYSTEMS AND CODES

c) 1 0 0 1 4 0 0 0 0

1 0 0

1408 = 001 100 0002 d) 7 1 1 1 2 5 6 1 1 0

0 1 0

1 0 1

72568 = 111 010 101 1102

BINARY TO OCTAL CONVERSION Example: Convert each of the following binary numbers to octal. a) 110 101 c) 100 110 011 101 b) 101 111 001 d) 011 010 000 100

Solution:
a) 110 101 b) 101 111 001

c) 100 110 011 101

d) 0 1 1 010 000 100

Fatma Syazana Zaini, IKM Besut, 2010

28

UNIT 2: NUMBER SYSTEMS AND CODES

2.8

HEXADECIMAL NUMBERING SYSTEM

The hexadecimal number system has sixteen (16) digits. It is composed of 16 digits and alphabets characters. Each hexadecimal digit represents a 4-bit binary number as listed in table 2. Hexadecimal is widely used in computer and microprocessor application.
DECIMAL 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 BINARY 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Table 2 HEXADECIMAL 0 1 2 3 4 5 6 7 8 9 A B C D E F

Fatma Syazana Zaini, IKM Besut, 2010

29

UNIT 2: NUMBER SYSTEMS AND CODES

BINARY TO HEXADECIMAL CONVERSION

Example 1:
Convert the following binary numbers to hexadecimal.

Solutions;
a) 1100 1010 0101 0111 b) 11 1111 0001 0110 1001

1100 1010 0101 01112 = CA5716

11 1111 0001 0110 10012 = 3F16916

HEXADECIMAL TO BINARY CONVERSION

Example 1:
Determine the binary numbers for the following hexadecimal numbers.

a)

10A416 1 0 0 0 1 0 0 0 0 0 A 4 1 0 1 0 0 1 0 0

10A416 = 0001 0000 1010 01002

Fatma Syazana Zaini, IKM Besut, 2010

30

UNIT 2: NUMBER SYSTEMS AND CODES

b)

CF8E16 C 1 1 0 0 1 1 1 1 F 8 E 1 0 0 0 1 1 1 0

CF8E16 = 1100 1111 1000 11102

c)

974216 9 1 0 0 1 0 1 1 1 7 4 2 0 1 0 0 0 0 1 0

974216 = 1001 0111 0100 00102

DECIMAL TO HEXADECIMAL CONVERSION To convert decimal numbers to hexadecimal, the decimal numbers are divided by 16 using the same repeated-division-method. Example 1 : Convert 4428910 to hexadecimal numbers.

Solution:
Remain

16 16 16 16

44289 2768 173 10 0

1 0 13 = D 10 = A

4428910 = A D 0 1

4428910 = AD0116

Fatma Syazana Zaini, IKM Besut, 2010

31

UNIT 2: NUMBER SYSTEMS AND CODES

For fractional decimal number, repeated-multiplication-method is used. Example 1: Convert 0.678510 to hexadecimal numbers.

Carry 0.6785 0.856 0.696 0.136 16 16 16 16 = 0.856 = 0.696 = 0.136 = 0.176 10 13 11 2

. A D B2

0.678510 = 0.ADB2

HEXADECIMAL TO DECIMAL CONVERSION Example : Convert A5C1.0116 to decimal numbers.

Solutions:
Weight Hex Number 163 A 162 5 161 C 160 1. 16-1 0 16-2 1

A5C1.0116 = 10 163 + 5 162 + 12 161 + 1 160 + 1 16-2 = 42433.0039

REMEMBER:
For hexadecimal system, if remainder larger than 9, replace as follow: 10 = A 11 = B 12= C 13 = D 14 = E 15 = F

Fatma Syazana Zaini, IKM Besut, 2010

32

UNIT 2: NUMBER SYSTEMS AND CODES

OCTAL TO HEXADECIMAL CONVERSION To convert from octal to hexadecimal number, you can use oct-dec-oct method or oct-bin-hex method.

Example:
Convert 74218 to hexadecimal number.

Solution:

Octal Number

Step 1: Expand each octal digits to three binary bit Step 2: binary Result in

Step 3: Group in four

Step 4: Convert

74218 = F1116

Fatma Syazana Zaini, IKM Besut, 2010

33

UNIT 2: NUMBER SYSTEMS AND CODES

HEXADECIMAL TO OCTAL CONVERSION Same with octal to hexadecimal conversion, you can either use hex-dec-oct method or hex-bin-oct method. Example: Convert E64B16 to octal number.

Solution:

Hex Number

Step 1: Expand each octal digits to four binary bit Step 2: Result in binary

1 1 1 0

0 1 1 0

0 1 0 0

1 0 1 1

1 1 1 0 0 1 1 0 0 1 0 0 1 0 1 1

Step 3: Group in three

1 1 0

0 1 1

0 0 1

0 0 1

0 1 1

Step Convert

4:

1 6 3 1 1 3

E64B16 = 1631138

Fatma Syazana Zaini, IKM Besut, 2010

34

UNIT 2: NUMBER SYSTEMS AND CODES

2.9

DECIMAL NUMBERS IN BINARY CODED DECIMAL (BCD) FORM

BCD is a way to express each of the decimal digits with a binary code. BCD means that each decimal digit 0 through 9 is represented by a binary code of four bits. There are only ten code groups in the DCB system. To express any decimal number in BCD, replace each decimal digit with the appropriate 4-bit code. DECIMAL DIGIT 0 1 2 3
4 5 6 7 8 9
Table 3

BCD 0000 0001 0010 0011


0100 0101 0110 0111 1000 1001

Example : Convert each of the following numbers to BCD. a) 35 b) 98 c) 170 d) 2469

Solutions:
a) 3 0 0 1 1 5 0 1 0 1

35 = 0011 0101BCD
Fatma Syazana Zaini, IKM Besut, 2010

35

UNIT 2: NUMBER SYSTEMS AND CODES

b) 9 1 0 0 1 8 1 0 0 0

98 = 1001 1000BCD

c) 1 0 0 0 1 0 1 7 1 0 1 0 0 0 0

170 = 0001 0111 0000BCD

d) 2 0 0 1 0 0 1 0 4 0 6 0 9 1 1 0 1 0 0 1

2469 = 0010 0100 1001 1001BCD

Example : Convert each of the following BCD to decimal. a) 1000 0110 b) 0011 0101 0001

Solutions:
a) 1000 0110 b) 0011 0101 0001

1000 0110BCD = 8610

0011 0101 0001BCD = 35110

Fatma Syazana Zaini, IKM Besut, 2010

36

UNIT 2: NUMBER SYSTEMS AND CODES

2.10

ADD BCD NUMBERS

BCD is a numerical code and can be used in arithmetic operation. Addition is the most important operation because the other three operations (subtraction, multiplication and division) can be accomplished by the use of addition.

Step Procedure To Add BCD Number Step 1: Step 2: Step 3: Add the two BCD number using rules for binary addition. if a 4-bit sum is equal or less than 9, it is a valid BCD number. if a 4-bit sum is greater than 9, or if a carry out of the 4-bit group is generated, it is an invalid result. Add 6 (0110) to the 4-bit sum in order to skip the six invalid states and return the code to BCD. If a carry result when 6 is added, simply add the carry to the next 4-bit group.

Example 1 :
Add the following BCD numbers: a. 0011 + 0100 0 0 1 1 0 1 0 0 0 1 1 1

b. 0010 0011 + 0001 0101 0 0 1 0 0 0 0 1 0 0 1 1 0 0 1 1 0 1 0 1 1 0 0 0


1 1 1

Fatma Syazana Zaini, IKM Besut, 2010

37

UNIT 2: NUMBER SYSTEMS AND CODES

c. 1000 0110 + 0001 0011 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 0 0 0 1 1 1 0 0 1


1 1

d. 0100 0101 0000 + 0100 0001 0111 0 1 0 0 0 1 0 0 1 0 0 0


1

0 1 0 1 0 0 0 1 0 1 1 0

0 0 0 0 0 1 1 1 0 1 1 1

Example 2: Add the following BCD numbers: a. 1001 + 0100 1 0 1 0 0 0 1 1 1 0 3 0 0 0 1 1 1 0 1 0 1

+ + 0

Invalid BCD number (>9) Add 0110 (6)

0 1

b. 1001 + 1001 1 1 0 0 1 0 0 0 1 0 8 0 0 1 1 0
1

+ 1 + 0 0 0 1 1

1 1 0 0 0

Invalid because of carry Add 0110 (6)

Fatma Syazana Zaini, IKM Besut, 2010

38

UNIT 2: NUMBER SYSTEMS AND CODES

c. 0001 0110 + 0001 0101


1 1

0 0 0 1 + 0 0 0 1 0 0 1 0 + 0 0 1 1 3

0 1 1 0 0 1 0 1 1 0 1 1 0 1 1 0 0 0 0 1 1
Right group is invalid (>9), left group is valid Add 0110 (6)

d. 0110 0111 + 0101 0011


1 1 1 1

+ + 0 0 0 1 1

0 1 1 0 0 1 0 1 1 0 1 1 0 1 1 0 0 0 1 0 2

0 1 1 1 0 0 1 1 1 0 1 0 0 1 1 0 0 0 0 0 0
Both groups are invalid (>9) Add 0110 (6) to both group

Fatma Syazana Zaini, IKM Besut, 2010

39

UNIT 2: NUMBER SYSTEMS AND CODES

2.11

GRAY AND ASCII CODES

THE GRAY CODES

There are many specialized codes used in digital systems. Some codes are strictly numeric like BCD and others are alphanumeric that is they used to represent numbers, letters, symbols and instructions. The code introduced in this topic is the Gray code. The Gray Code is un-weighted and is not an arithmetic code: that is there are no specific weights assigned to the bit positions. The important feature of the Gray code is that it exhibits only a single bit change from one code word to the next in sequence. This property is important in many applications, such as shaft position encoders, where error susceptibility increases with the number of bit changes between adjacent numbers in a sequence. Table 4 is a listing of the 4-bit Gray code for decimal numbers 0 through 15. Binary numbers are shown in the table 4 for reference.

DECIMAL 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

BINARY 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Table 4

GRAY CODE 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000

Fatma Syazana Zaini, IKM Besut, 2010

40

UNIT 2: NUMBER SYSTEMS AND CODES

BINARY TO GRAY CODE CONVERSION Procedure: i. ii. The most significant bit (left-most) is the Gray code is the same as the corresponding MSB in the binary number. Going from left to right, add each adjacent pair of binary code bits to get the next Gray code bit. Discard carries.

Example 1:
Convert the binary number 10110 to Gray code.

1 1

0 1

1 1

1 0

0 1

Binary Gray

Example 2:
Convert the binary number 1100 0110 to Gray code

1 + 1 + 0 + 0 + 0 + 1 + 1 + 0 Binary 1 0 1 0 0 1 0 1 Gray

GRAY TO BINARY CONVERSION Procedure: i. ii. The most significant bit (left-most) in the binary code is the same as the corresponding bit in the Gray code. Add each binary code bit generated to the Gray code bit in the next adjacent position. Discard carries.

Fatma Syazana Zaini, IKM Besut, 2010

41

UNIT 2: NUMBER SYSTEMS AND CODES

Example1:
Convert the Gray code below to binary. a. 11011

b. 1011 1111

ASCII CODES

ASCII is the abbreviation for American Standard Code for Information Interchange. Pronounce askee. ASCII is a universally accepted alphanumeric code used in most computers and other electronic equipment. Most computer keyboards are standardized with the ASCII. When we enter a letter, a number or control command, the corresponding ASCII code goes into the computer.

ASCII has 128 characters and symbols represented by a 7-bit binary code. Actually ASCII can be considered an 8-bit code with the MSB always 0. This 8-bit code is 00 through 7F in hexadecimal.

The first thirty-two ASCII characters are non-graphic commands that are never printed or displayed and are used only for control purposes.

Examples of the control characters are null, line feed, start of text and escape. The other characters are graphic symbols that can be printed or displayed and include the letters of the alphabet (lowercase and uppercase), the ten decimal digits, punctuation signs and other commonly used symbols.

Fatma Syazana Zaini, IKM Besut, 2010

42

UNIT 2: NUMBER SYSTEMS AND CODES

Table 5 is a listing of the ASCII code showing the decimal, hexadecimal and binary representations for each character and symbol. The left section of the table lists the names of the 32-control character (00 through 1F hexadecimal).

Table 5

The first thirty-two codes in the ASCII table represent the control characters. These are used to allow devices such as a computer and printer to communicate with each other when passing information and data. Table 2 lists the control characters and the control key function that allows them to be entered directly from an ASCII keyboard by pressing the control key (CTRL) and the corresponding symbol.

Fatma Syazana Zaini, IKM Besut, 2010

43

UNIT 2: NUMBER SYSTEMS AND CODES

The extended ASCII contains characters in the following general categories: a. b. c. d. e. f. g. Foreign (non-English) alphabetic characters Foreign currency symbols Greek Letter Mathematical symbols Drawing characters Bar graphing characters Shading character

Example 1:
Determine the binary ASCII codes that are entered from the computers keyboard when the following BASIC program statement is typed in also express each code in hexadecimal. 20 PRINT A= ; X

Solution;
The ASCII code for each symbol is found in table 1.

Symbol 2 0 Space P R I N T Space A = ; X

Binary 011 0010 011 0000 010 0000 101 0000 101 0010 100 1001 100 1110 101 0100 010 0000 010 0010 100 0001 011 1101 010 0010 011 1011 101 1000

Hexadecimal 3216 3016 2016 5016 5216 4916 4E16 5416 2016 2216 4116 3D16 2216 3B16 5816

Fatma Syazana Zaini, IKM Besut, 2010

44

UNIT 2: NUMBER SYSTEMS AND CODES

Fatma Syazana Zaini, IKM Besut, 2010

45

UNIT 2: NUMBER SYSTEMS AND CODES

SUMMARY

In this topic, students have learned the numeric quantities occur naturally in analogue but must be converted to digital form to be used by computers or digital circuitry. Student must understand that the binary numbering system is used in digital systems because the 1s and 0s are easily represented by ON or OFF transistors, which output 0volt for zero(0) and 5volt for one(1). Students also must know that the ASCII is used by computers to represent all letters, numbers and symbols in digital form.

EXERCISE
1. Convert each decimal number to binary. a. 23 b. 57 c. 45 2. Convert the following binary to decimal a. 101102 b. 1101 10112 c. 110 11112 d. 1001 11012 3. Determine the 1s complement of each binary number: a. 0001 1010 b. 1111 0111 c. 1000 1101 4. Determine the 2s complement of each binary number: a. 0001 0110 b. 1111 1100 c. 1001 0001
Fatma Syazana Zaini, IKM Besut, 2010

46

UNIT 2: NUMBER SYSTEMS AND CODES

5. Using a. b. c. 6. Using a. b. c.

the rules for binary addition, evaluate the following 11112 + 1002 01112 + 10102 11002 + 0102 the rules for binary subtraction evaluate the following. 10002 00112 01012 00102 11112 - 11002

7. Multiply 0111 1111 by 0000 0101. 8. Convert the following decimal numbers to binary: a. 468 b. 7238 c. 56248 9. Convert the following binary numbers to octal: a. 1 1010 11112 b. 10 0110 00102 c. 101 1111 10012 10. Convert the following decimal numbers to BCD: a. 6 b. 15 c. 273 d. 849 11. What a. b. c. decimal numbers are represented by each BCD code? 1000 10012 0010 0111 10002 0001 0101 01112

12. Convert the following binary numbers to the Gray code: a. 11002 b. 10102 c. 110102

Fatma Syazana Zaini, IKM Besut, 2010

47

UNIT 2: NUMBER SYSTEMS AND CODES

13. Convert the following Gray codes to binary: a. 10002 b. 10102 c. 111012

14. What is the ASCII representation for each of the following characters? Express each as a bit and in hexadecimal notation. a. K b. r c. $ d. +

REFERENCES

1. Digital System Principle And Applications, Tocci, R.J, Prentice Hall international 2. Digital Fundamentals, Floyd T.L, Merrill Publishing 3. BPL(K) Module TFV 2033 Digital Electronics 1 4. Digital Electronics: Teaching Module, KUITHO

Fatma Syazana Zaini, IKM Besut, 2010

48

You might also like