Você está na página 1de 49

CHAPTER 1

NUMBER SYSTEMS
& CODES

DIGITAL SYSTEM 1
ECE 351
1.1) NUMBER SYSTEMS
 Decimal number
 Binary number
 Octal number
 Hexadecimal Number

ECE 351 Chapter 1: Number Systems and Codes 2


Decimal
Number

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

ECE 351 Chapter 1: Number Systems and Codes 3


Decimal Binary
Number Number

BINARY NUMBER 0 0
1 1
2 10
 Symbol : 0, 1 3 11
 Also called base 2 system 4 100
5 101
 Commonly used by computer 6 110
 Each binary digit is called a bit 7 111
8 1000
 Largest decimal number = 2n-1 9 1001
where n is the no of bits used. 10 1010
e.g 8 bits ,largest decimal number 11 1011
12 1100
= 28-1=255
13 1101
14 1110
 e.g. 10102 to show base 2 15 1111
16 1 0 0 0 0 0
LSB
ECE 351 MSB Chapter 1: Number Systems and Codes 4
OCTAL NUMBER Decimal
0
Octal
0
1 1
 Symbol : 0, 1, 2, 3,4, 5, 6, 7 2 2
 Also called base 8 system 3 3
4 4
 Used in computer and micro 5 5
processing application to 6 6
simplify binary representation 7 7
 Method of grouping binary 8 10
number in groups of 3 9 11
10 12
 e.g. 128 11 13
subscript 8 shows that number 12 is in
12 14
base 8.
13 15
14 16
15 17
ECE 351 Chapter 1: Number Systems and Codes
16 20 5
HEXADECIMAL
NUMBER Decimal Hexadecimal
0 0
1 1
 Symbol : 0, 1, 2, 3,4, 5, 6, 7, 2 2
8, 9, A, B, C, D, E, F
3 3
 Also called base 16 system 4 4
 Used in computer and micro 5 5
processing application to 6 6
simplify binary representation
7 7
 Method of grouping binary 8 8
number in groups of 4
9 9
 8 bits = 1 byte 10 A
 e.g. A716 or A7H 11 B
12 C
13 D
14 E
15 F
ECE 351 Chapter 1: Number Systems and Codes 6
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 7
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 8


NUMBER CONVERSIONS (cont’d)

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


8.210 => ?2

2 8
LSB 0.2 x 2 = 0.4  0.0
2 4 0
0.4 x 2 = 0.8  0.00
2 2 0
0.8 x 2 = 1.6  0.001
remainders
2 1 0
form the 0.6 x 2 = 1.2  0.0011
2 0 1
binary
MSB

Answer : 8.210 => 1000. 0011 2


ECE 351 Chapter 1: Number Systems and Codes 9
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 10


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.4
0.48 x 8 = 3.84  0.43
8 1 4 0.84 x 8 = 6.72  0.436
8 0 1
MSB

Anwer= 14.4368

ECE 351 Chapter 1: Number Systems and Codes 11


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 12


NUMBER CONVERSIONS (Cont’d)
3b) Binary Octal

1) 110101102 = 3268 011010110


3 2 6

2) 100010.12 = 62.4 8 110010.100


6 2 . 4

ECE 351 Chapter 1: Number Systems and Codes 13


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 14


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 15
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 16


NUMBER CONVERSIONS (Cont’d)
5b) Binary Hexadecimal

1) 11101001102 = 3A616 001110100110


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

ECE 351 Chapter 1: Number Systems and Codes 17


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 18


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

ECE 351 Chapter 1: Number Systems and Codes 19


1.3a) ARITHMETIC
OPERATION IN BINARY

ECE 351 Chapter 1: Number Systems and Codes 20


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 21


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 22
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 23


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 24


SIGN MAGNITUDE
 Left most bit us the sign bit.
 Others are magnitude bits
 0 represent positive
 1 represent negative Sign bit

00011001
Magnitude bits

ECE 351 Chapter 1: Number Systems and Codes 25


SIGN MAGNITUDE (cont’d)
Example:-

 Represent -25 decimal into straight


binary signed number.

ECE 351 Chapter 1: Number Systems and Codes 26


ARITHMETIC OPERATIONS WITH SIGNED
NUMBERS

•1’s complement
•2’s complement

*How many binary digits will be required for


computational will be required for the
computational is determined by the lasrgest
number (including the answer)

ECE 351 Chapter 1: Number Systems and Codes 27


ARITHMETIC OPERATIONS WITH SIGNED
NUMBERS
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
0010001

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

-0010001 answer

ECE 351 Chapter 1: Number Systems and Codes 28


ARITHMETIC OPERATIONS WITH SIGNED
NUMBERS (cont’d)
Subtraction using 2’s complement

 Let X = 1010100 , Y = 1000011


1010100 X
+ 0111101 2's complement of Y
X-Y
10010001 Discard end carry
0010001

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

-0010001 answer

ECE 351 Chapter 1: Number Systems and Codes 29


NUMBER CODES
 BCD
 Excess-3 Code
 ASCII Code
 Gray code
 Seven Segment Display

ECE 351 Chapter 1: Number Systems and Codes 30


NUMBER CODES (cont’d)

BCD (binary-coded-decimal)
- weighted code
- also known as 8421 BCD code
- is used to represent each of 10 decimal digits as a 4-bit binary
code
- convert each decimal digit to its 4-bit binary code
- only 0000 ~ 1001 are used.
- BCD code does not use numbers 1010, 1011, 1100, 1101, 1110,
1111
- BCD is not a straight binary number

decimal 8 7 4

BCD 1000 0111 0100


ECE 351 Chapter 1: Number Systems and Codes 31
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 32


NUMBER CODES (cont’d)
Excess-3 Code (XS-3)
numbers are represented as decimal digits
and each digit is represented by four bits as
the BCD value plus 3 (the "excess" amount):

ECE 351 Chapter 1: Number Systems and Codes 33


Decimal Binary Decimal Binary Decimal Binary Decimal Binary

−3 0000 1 0100 5 1000 9 1100

−2 0001 2 0101 6 1001 10 1101

−1 0010 3 0110 7 1010 11 1110

0 0011 4 0111 8 1011 12 1111

ECE 351 Chapter 1: Number Systems and Codes 34


Example:-
XS-3 Code
1. Convert 0110100000111001XS-3 to its
decimal equivalent.
2. Convert 13710 into XS-3 code.

ECE 351 Chapter 1: Number Systems and Codes 35


NUMBER CODES (cont’d)
Gray Code
This is a variable weighted code and is cyclic. This means that it is
arranged so that every transition from one value to the next value
involves only one bit change. The gray code is sometimes referred to
as reflected binary, because the first eight values compare
with those of the last 8 values, but in reverse order

ECE 351 Chapter 1: Number Systems and Codes 36


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 37
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 38


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 39


NUMBER CODES (cont’d)
ACSII code
 Most widely used ACSII code
 American Standard Code for Information
Interchange
 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 40
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(97).

ECE 351 Chapter 1: Number Systems and Codes 41


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 42


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 43


NUMBER CODES (cont’d)
7-segment display

ECE 351 Chapter 1: Number Systems and Codes 44


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

ECE 351 Chapter 1: Number Systems and Codes 45


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

ECE 351 Chapter 1: Number Systems and Codes 46


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 <- e.g of even parity
 Odd Parity
 Total number ‘1’ = odd
 Even Parity
 Total number ‘1’ = even

 Odd parity : standard for synchronous transmission


 Even parity : standard for asynchronous transmission

ECE 351 Chapter 1: Number Systems and Codes 47


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 48
Example:–
Parity Code

1. For the following binary number, determine


parity bit if even parity is used.
2. For the following binary number, determine
parity bit if odd parity is used.
 0111
 1101
 1010
 1111
 1000
 0000

ECE 351 Chapter 1: Number Systems and Codes 49

Você também pode gostar