0% found this document useful (0 votes)
85 views50 pages

Digital System Topic 1

This document provides information about number systems and number conversions. It discusses decimal, binary, octal and hexadecimal number systems. It describes how to convert between these different number bases, including methods for converting decimal numbers to binary and vice versa. Conversion between other bases like binary to octal and octal to decimal are also covered. The document also discusses arithmetic operations in different number systems and coding systems like BCD, ASCII and gray codes.
Copyright
© © All Rights Reserved
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)
85 views50 pages

Digital System Topic 1

This document provides information about number systems and number conversions. It discusses decimal, binary, octal and hexadecimal number systems. It describes how to convert between these different number bases, including methods for converting decimal numbers to binary and vice versa. Conversion between other bases like binary to octal and octal to decimal are also covered. The document also discusses arithmetic operations in different number systems and coding systems like BCD, ASCII and gray codes.
Copyright
© © All Rights Reserved
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/ 50

CHAPTER 1

NUMBER SYSTEMS
AND CODES
Lesson Outcome
At the end of the lesson, students
should be able to describe and
explain:
• Number System: Decimal, Binary, Octal and Hexadecimal Numbers.
• Number Conversion
 Decimal to Binary and Binary to Decimal
 Binary to Octal and Octal to Binary
 Binary to Hexadecimal and Hexadecimal to Binary
• Arithmetic Operation In Binary, Octal and Hexadecimal
• 1st Compliment and 2nd Compliment of Binary Numbers
• Arithmetic Operations with Complements
• Signed Numbers
• Number Codes: BCD, ASCII, Gray and Seven Segment Display
• Parity Method For Error Detection
1.1) NUMBER SYSTEMS
• Decimal number
• Binary number
• Octal number
• Hexadecimal Number

ECE 351 Chapter 1: Number Systems and Codes 9


DECIMAL NUMBER Decimal
Number
0
1
• Symbol : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9… 2
• Also called base 10 system or radix of 10 3
• e.g. 1210 subscript 10 shows that number 4
in base 10. 5
6
• Commonly used in human daily activities.
7
8
9
10
11
12
13
14
15
16

ECE 351 Chapter 1: Number Systems and Codes 10


BINARY NUMBER
Decimal Binary
Number Number

• Symbol : 0, 1 0 0000
1 0001
• Also called base 2 system 2 0010
3 0011
• Commonly used by computer 4 0100
• Each binary digit is called a bit 5 0101
6 0110
• Largest decimal number = 2n-1 7 0111
where n is the no of bits used. 8 1000
9 1001
e.g 8 bits ,largest decimal number 10 1010
= 28-1=255 11 1011
12 1100
13 1101
• e.g. 10102 to show base 2 14 1110
15 1111
LSB 16 10000
MSB
ECE 351 Chapter 1: Number Systems and Codes 11
OCTAL NUMBER
Decimal Octal
Number Number
• Symbol : 0, 1, 2, 3,4, 5, 6, 7 0 0
• Also called base 8 system 1 1
2 2
• Used in computer and micro 3 3
processing application to 4 4
simplify binary representation 5 5
6 6
• Method of grouping binary 7 7
number in groups of 3 8 10
9 11
• e.g. 128
10 12
subscript 8 shows that number 12 is in
11 13
base 8.
12 14
13 15
14 16
15 17
16 20
ECE 351 Chapter 1: Number Systems and Codes 12
HEXADECIMAL
Decimal Octal
NUMBER Number Number
0 0
• Symbol : 0, 1, 2, 3,4, 5, 6, 7,
1 1
8, 9, A, B, C, D, E, F
2 2
• Also called base 16 system 3 3
• Used in computer and micro 4 4
processing application to 5 5
simplify binary representation 6 6
• Method of grouping binary 7 7
number in groups of 4 8 10
• 8 bits = 1 byte 9 11
10 A
• e.g. A716 or A7H 11 B
12 C
13 D
14 E
15 F
16 10
ECE 351 Chapter 1: Number Systems and Codes 13
1.2) NUMBER CONVERSION

1a) Binary Decimal


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

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


= 13.2510

1b) Decimal Binary


2 conversion methods : i) reverse process
ii) repeated division by 2

i) Reverse process method


e.g , 4510 = 32 + 8 + 4 + 1 = 25 + 0 + 23 + 22 + 0 + 20
1 0 1 1 0 12
ECE 351 Chapter 1: Number Systems and Codes 14
NUMBER CONVERSIONS (cont’d)
ii. Repeated division by 2 method

2 25 LSB
2 12 1
1) 2510 = ? 2 = 2 6 0
remainders
110012 2 3 0 form the
Answer =
2 1 1 binary
0 1
MSB

ECE 351 Chapter 1: Number Systems and Codes 15


NUMBER CONVERSIONS (cont’d)

2) Convert 8.210 to binary number (up to 4 decimal points).


8.210 => ?2
0.2 x 2 = 0.4 

2 8 0.4 x 2 = 0.8 
LSB
2 4 0 .0011
2 2 0 0.8 x 2 = 1.6 
2 1 0 remainders
2 0 1
form the 0.6 x 2 = 1.2 
binary
MSB

Answer : 8.210 => 1000. 0011 2

ECE 351 Chapter 1: Number Systems and Codes 16


NUMBER CONVERSIONS (cont’d)

2a) Octal Decimal


1) 3728 = 3 x 82 + 7 x 81 + 2 x 80 =>
answer = 25010

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


answer= 20.7510
2b) Decimal Octal
8 266
1) 26610 = ?
8 33 2
Answer= 4128
remainders form
8 4 1 the octal
0 4

ECE 351 Chapter 1: Number Systems and Codes 17


NUMBER CONVERSIONS (cont’d)
2b) Decimal Octal ( cont’d)
2) 12.5610 = ?8 (answer should be up to 3 decimal points)

remainders
8 12 LSB 0.56 x 8 = 4.48
0.48 x 8 = 3.84 .436
8 1 4 0.84 x 8 = 6.72
8 0 1
MSB

Anwer= 14.4368

ECE 351 Chapter 1: Number Systems and Codes 18


NUMBER CONVERSIONS (Cont’d)

3a) Octal Binary


Convert each octal digit to its 3-bit binary equivalent

1) 4728 = > 4 7 2
Answer=1001110102
100 111 010

2) 624.58 = 6 2 4 . 5
Answer=110010100.1012
110 010 100 . 101

ECE 351 Chapter 1: Number Systems and Codes 19


NUMBER CONVERSIONS (Cont’d)

3b) Binary Octal

1) 110101102 = 3268 011010110


3 2 6

2) 100010.12 = 42.48
100010.10
4 2 . 4

ECE 351 Chapter 1: Number Systems and Codes 20


NUMBER CONVERSIONS (Cont’d)

4a) Hexadecimal Decimal

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

2) 2A.F16 = 2 x 162 + 10 x 161 + 15 x 16-1


= 672.937510

ECE 351 Chapter 1: Number Systems and Codes 21


NUMBER CONVERSIONS (Cont’d)
4b) Decimal Hexadecimal

42310 = 1A716 16 423


16 26 7
remainders form
16 1 10 = A the hexadecimal

0 1

16 204.125
204.12510 = CC.216
16 12 12 = C
0 12 = C

0.125 x 16 = 2 . 0

ECE 351 Chapter 1: Number Systems and Codes 22


NUMBER CONVERSIONS (Cont’d)

5a) Hexadecimal Binary


Convert each hex digit to its 4-bit binary equivalent

9 F 2
1) 9F216 = 1001111100102
1001 1111 0010

A . .0 E
2) A.0E16 = 1010.000011102
1010. 0000 1110

ECE 351 Chapter 1: Number Systems and Codes 23


NUMBER CONVERSIONS (Cont’d)

5b) Binary Hexadecimal

1) 11101001102 = 3A616 001110100110


3 10 6
=
A
2) 100.11011102 = 4.DC16
100.1101110
4 . 13 C
=D

ECE 351 Chapter 1: Number Systems and Codes 24


SUMMARY
1. Conversion from binary/octal/hex to decimal : weighted sum of
each digit position

2. Conversion from decimal to binary/octal/hex : repeatedly


dividing by 2/8/16 and collecting the remainder

3. Conversion from binary to octal/hex : group the bits in groups


of 3/4 and convert each group into correct octal/hex digit

4. Conversion from octal/hex to binary : convert each digit into its


3/4 bit equivalent

5. Conversion from octal to hex / hex to octal : first convert to


binary then convert binary into desired number systems

ECE 351 Chapter 1: Number Systems and Codes 25


1.3) ARITHMETIC OPERATION
IN
a) Binary
b) Octal
c) Hexadecimal

ECE 351 Chapter 1: Number Systems and Codes 26


1.3a) ARITHMETIC
OPERATION IN BINARY
0+0=0 carry 0
a) Addition 0+1=1 carry 0
1+0=1 carry 0
I I I I
0+0=0 carry
1+1=0 carry01
1110 1100
0+1=1 carry
1+1+1=1 0 1
carry
+ 110 0110 1+0=1 carry 0
1+1=0 carry 1
1 0101 0010
1+1+1=1 carry 1

b) Subtraction 0+0=0 carry 0


0+1=1 carry 0
0 I I 0 0 0 1+0=1 carry 0
10001101 0011 0 – 1+1=0
0=0 borrow
carry0 1
0 – 1+1+1=1
1=1 borrowcarry
1 1
– 1 0110 1001 1 – 0=1 borrow 0
111 0110 1010 1 – 1=0 borrow 0

ECE 351 Chapter 1: Number Systems and Codes 27


1.3b) ARITHMETIC
OPERATION IN OCTAL
a) Addition b) Subtraction

178 308
+ 78 - 78
268 218

328 468
+ 78 - 78
418 378

ECE 351 Chapter 1: Number Systems and Codes 28


ARITHMETIC OPERATION IN
HEXADECIMAL
a) Addition
A 102
B 9
10B

b) Subtraction
A 300
B 28
2D8
ECE 351 Chapter 1: Number Systems and Codes 29
COMPLEMENTS

• Complements are used to simplify the


subtraction operation and logical operation.
• Two types of complements for binary
numbers:
– 1’s Complement
– 2’s Complement

ECE 351 Chapter 1: Number Systems and Codes 30


1’s and 2’s COMPLEMENT OF BINARY
NUMBERS
• 1’s complement of a
binary number is found
by changing all 1s to
0s and all 0s to 1s 00011001 Binary number

• 2,s complement is
found by adding 1 to 11100110 1's complement
the LSB of the 1’s
complement
or
leave all LSB ‘0’s and the 11100111 2's complement

first ‘1’ unchanged and


replaced 1’s with 0’s and
the 0’s with 1’s in all

ECE 351 Chapter 1: Number Systems and Codes 31


ARITHMETIC OPERATIONS WITH COMPLEMENTS

Subtraction using 1’s complement


• Let X = 1010100 , Y = 1000011
1010100 X
+ 0111100 1's complement of Y
X-Y
10010000
+ 1 end-around carry
X–Y= 0010001

1000011 Y
Y-X + 0101011 1's complement of X
1101110 no end carry

Y–X= -0010001 ans = – (1's comp. of 1101110)

ECE 351 Chapter 1: Number Systems and Codes 32


ARITHMETIC OPERATIONS WITH COMPLEMENTS

Subtraction using 2’s complement


• Let X = 1010100 , Y = 1000011
1010100 X
+ 0111101 2's complement of Y
X-Y
10010001
–10000000 discard end carry
X–Y= 0010001

1000011 Y
Y-X + 0101100 2's complement of X
1101111 no end carry

Y–X= -0010001 ans = – (2's comp. of 1101111)

ECE 351 Chapter 1: Number Systems and Codes 33


SIGNED NUMBERS
• A signed binary number consists of
magnitude and sign information.
• Three forms are used to represent
signed numbers in binary:
– Sign magnitude
– 1’s complement
– 2’s complement

ECE 351 Chapter 1: Number Systems and Codes 34


SIGNED MAGNITUDE
Sign bit

• Sign bit - the most left bit


00011001
• Others are magnitude bits
Magnitude bits

• 0 - represent positive
• 1 - represent negative
1010 = 0000 10102

Sign bit 1 for


• Example: (-10)10 = (1000 1010)SM 000010102

ECE 351 Chapter 1: Number Systems and Codes 35


SIGNED - 1’s COMPLEMENT

• Sign bit for the 1’s Complement number


1010 = 0000 10102

Sign bit 1 for 1’s


• Example: (-10)10 = (1111 0101)S1C complement of
000010102

ECE 351 Chapter 1: Number Systems and Codes 36


SIGNED - 2’s COMPLEMENT

• Sign bit for the 2’s Complement number


1010 = 0000 10102

Sign bit 1 for 2’s


• Example: (-10)10 = (1111 0110) S2C complement of
000010102

ECE 351 Chapter 1: Number Systems and Codes 37


NUMBER CODES
• BCD
• Gray code
• ASCII Code
• Seven Segment Display

ECE 351 Chapter 1: Number Systems and Codes 38


NUMBER CODES (cont’d)
Decimal 8421
Number BCD
0 0000
1. BCD (binary-coded-decimal) 1 0001
- weighted code 2 0010
- also known as 8421 BCD code 3 0011
- is used to represent each of 10 decimal 4 0100
5 0101
- digits as a 4-bit binary code 6 0110
- convert each decimal digit to its 4-bit binary 7 0111
code 8 1000
- only 0000 ~ 1001 are used. 9 1001
10 0001 0000
- BCD code does not use numbers 11 0001 0001
1010, 1011, 1100, 1101, 1110, 1111 12 0001 0010
13 0001 0011
decimal 8 7 4 14 0001 0100
15 0001 0101
BCD 1000 0111 0100 16 0001 0110
ECE 351 Chapter 1: Number Systems and Codes 39
Example:-
BCD
1. Convert 0110100000111001(BCD) to
its decimal equivalent.
2. Convert 13710 into BCD and binary.
Notes the difference.

ECE 351 Chapter 1: Number Systems and Codes 40


NUMBER CODES (cont’d)
Decimal Binary Gray
2. Gray Code Number Number Code
- Non-weighted binary code 0 0000 0000
1 0001 0001
- Cyclic arranged, so that every 2 0010 0011
transition 3 0011 0010
4 0100 0110
from one value to the next value 5 0101 0111
6 0110 0101
involves only one bit change 7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000

ECE 351 Chapter 1: Number Systems and Codes 41


NUMBER CODES (cont’d)
Binary to Gray conversion
i. Write down the number in binary code
ii. The MSB of Gray is the MSB of binary code
iii. Add (using modulo 2) the next significant bit of the binary number to the
next significant bit of the binary number to obtain the next Gray code bit
iv. Continue step ‘iii’ right through the end

Note: modulo 2 arithmetic: this is binary addition with the carry ignored
1 0 1 1
0 0 1 + + + +
Binary + + + 1 0 1 1 0
0 0 1 0

Gray code 0 0 1 1 1 1 1 0 1

ECE 351 Chapter 1: Number Systems and Codes 42


NUMBER CODES (cont’d)
Gray to Binary conversion
i. Write down the number in gray code
ii. The MSB of binary is the MSB of Gray code
iii. Add (using modulo 2) the next significant bit of the binary number
to the next significant bit of the Gray code to obtain the next bit
iv. Continue step ‘iii’ right through the end

1 1 1 1 0 0 0 1
+ + + + + + + +
Gray code 1 0 0 1 1 1 0 0 1 1

Binary 1 1 1 0 1 0 0 0 1 0

ECE 351 Chapter 1: Number Systems and Codes 43


Example:-
Gray Codes
1. Convert the number 0101 (binary)
to its Gray code equivalent.
2. Convert 0101 (grey code) to its
binary equivalent.

ECE 351 Chapter 1: Number Systems and Codes 44


NUMBER CODES (cont’d)
3. ASCII Code

• American Standard Code for Information


Interchange
• Most widely used ACSII code
• Consists seven-bit code i.e. 27 = 128 possible
code groups
• 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.

ECE 351 Chapter 1: Number Systems and Codes 45


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

0 NUL SOH STX ETX EOT ENQ ACK BEL BS TAB LF VT FF CR SO SI

1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US

2 ! " # $ % & ' ( ) * + , - . /

3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

4 @ A B C D E F G H I J K L M N O

5 P Q R S T U V W X Y Z [ \ ] ^ _

6 ` a b c d e f g h i j k l m n o

7 p q r s t u v w x y z { | } ~ •

* The table is DECIMAL (i.e., characters appear normally) but is organized to be read in hexadecimal: Row numbers
[down] represent the first half of a HEX value and column numbers [across] represent the second half of a HEX value.
For example, the uppercase A is located at row 4 and column 1. Therefore, an upper case A in HEX would be 41. Said
another way, if I say "the value is HEX 41" I'm saying the value is uppercase A. But the proper way to write HEX 41 is:
0x41 (65), where "0x" means it's a HEX number, 41 is the row and column [value], and (65) means it is the 65th ASCII
character in the 0-127 list. -- BTW: Lowercase a in HEX is 0x61(98).

ECE 351 Chapter 1: Number Systems and Codes 46


Example:-
ASCII Code
1. Used ASCII Code table to find the
seven-bit ASCII code for the
character ( \ ).
2. Try for other characters

ECE 351 Chapter 1: Number Systems and Codes 47


NUMBER CODES (cont’d)
7-segment code
• Decode from machine language to decimal numbers
• Systems such as digital watches, calculator, pagers and
cellular phones make use of multi-segment display
• The most popular multi-segment display technique is the
7-segment display
• Decoder : convert 4-bit BCD into 7-segment code
• Common- anode : active low i.e. takes a LOW to turn
‘on’ (illuminate) a segment
• Common-cathode : active high i.e. cathodes of all
segments are tied together and connected to ground

ECE 351 Chapter 1: Number Systems and Codes 48


NUMBER CODES (cont’d)
7-segment display

ECE 351 Chapter 1: Number Systems and Codes 49


NUMBER CODES (cont’d)
7-segment display and decoder

ECE 351 Chapter 1: Number Systems and Codes 50


NUMBER CODES (cont’d)
7-segment display and decoder

ECE 351 Chapter 1: Number Systems and Codes 51


PARITY CODES
• Definition: A parity bit is a bit added to ensure that the number
of bits with the value one (‘1’) in a set of bits is even or odd.

• Purpose: Used to detect errors occur during transmission.

• 4th bit requires 5th bit as parity bit.

– Eg: 1001 - 0 1 0 0 1 <- even parity


– 1001 - 1 1 0 0 0 <- even parity (in error)

– Eg: 1001 - 0 1 0 0 0 <- odd parity


– 1001 - 1 1 0 0 1 <- odd parity (in error)
• Odd Parity
– Total number ‘1’ = odd
• Even Parity
– Total number ‘1’ = even

• Odd parity : standard for synchronous transmission


• 351Even parity : standard
ECE for1: asynchronous
Chapter transmission
Number Systems and Codes 52
PARITY GENERATOR
23 2 2 21 20 23 2 2 21 20

Parity bit Parity bit


(even) (odd)

4-bit even and odd parity generator


ECE 351 Chapter 1: Number Systems and Codes 53
Example:–
Parity Code

1. For the following binary number, determine


parity bit if even parity is used next to the
LSB.
2. For the following binary number, determine
parity bit if odd parity is used next to the
MSB.
– 0111
– 1101
– 1010
– 1111
– 1000
– 0000

ECE 351 Chapter 1: Number Systems and Codes 54


Revision Chapter 1
1. Conversion:
a) Find the equivalent binary and decimal numbers
for 6248.
b) Convert 638 to BCD and Gray code respectively.

2. Add the following unsigned numbers and state the


answers in decimal:
a) 2A16 and 1416 (add in hex)
b) 158 and 448 (add in octal)
c) 10102 and 10102 (add in bin)

55
3. Using 8-bit 2’s complement arithmetic, perform the
following operations, where A=478 and B=7E16.
a) A+B
b) A–B

4. Identify the equivalent octal number of each of the


following signed 2’s complement.
a) 1110010100
b) 01100101

56

You might also like