Sei sulla pagina 1di 69

Company

LOGO

DEE 1224
DIGITAL ELECTRONICS

CHAPTER 2
Number Systems and
Codes

www.company.com
Company
LOGO
TOPICS

• Number Systems
2.1 • Decimal, Binary, Octal, Hexadecimal

• Conversion between Number Systems


2.2

• Numbering Code
2.3

• Alphanumeric Code
2.4

• Signed Number
2.5

www.company.com
Company
LOGO
LEARNING OUTCOMES

Recognize different number systems: decimal,


binary, octal and hexadecimal.

Convert a number from one number system to


its equivalent in one of the other number
systems.

Apply arithmetic operations for each number


system.

Represent decimal numbers using BCD code

Express signed binary numbers in sign-


magnitude, 1’s complement and 2’s
complement.
www.company.com
Company
LOGO
Number Systems

• A number system can be specified by:


– Its base, b
– Its alphabet of a digit (e.g: C=12)

Most Significant Digit

(N)b = an-1bn-1 + an-2bn-2 + ... + a1b1 + a0b 0

Least Significant Digit

www.company.com
Company
LOGO
Decimal Number
System
• Represented by 10 digits (0-9)
• Base-10 system
• Value for each digit is determined by its digit
multiplied by 10 to the power of its position.

www.company.com
Company
LOGO
Decimal Number
System

103 102 101 100


2 3 4 1

(1x100) = 110

(4x101) = 4010

(3x102) = 30010

(2x103) = 200010

234110

www.company.com
Company
LOGO
Binary Number System

• Represented by 2 digits called bits (1 and 0).


• Base-2 system.
• Value for each digit is determined by its bit
multiplied by 2 to the power of its position.

www.company.com
Company
LOGO
Binary Number System

www.company.com
Company
LOGO
Binary Number System

• With n-bits, you can count up to a


number equal to: 2 n -1

• Representation according to number of


bits:
– 4-bits = 1 nibble
– 8-bits = 2 nibbles = 1 byte
– 16-bits = 4 nibbles = 2 bytes = 1 word

www.company.com
Company
LOGO
Octal Number System

• Represented by 8 digits (0-7)


• Base-8 system
• Value for each digit is determined by
its digit multiplied by 8 to the power of
its position.

www.company.com
Company
LOGO
Hexadecimal Number
System

• Represented by 16 digits (0-9 and A-F)


• Base-16 system
• Value for each digit is determined by
its digit multiplied by 16 to the power of
its position.

www.company.com
Company
LOGO Number Systems

www.company.com
Company
LOGO
Conversion Between
Number Systems
1. Conversions to 3. Binary conversions
decimal i. Binary to Octal
i. Binary to Decimal ii. Binary to Hex
ii. Octal to Decimal 4. Octal conversions
iii. Hex to Decimal i. Octal to Binary
2. Decimal 5. Hex conversions
conversions i. Hex to Binary
i. Decimal to Binary
ii. Decimal to Octal
iii. Decimal to Hex

www.company.com
Company
LOGO

Conversions to
Decimal
From binary, octal and hexadecimal

www.company.com
Company
LOGO
Binary to Decimal

(11101)2
= 2 +2 +2 +0+2
4 3 2 0

= 16 + 8 + 4 + 1
= (29)10

www.company.com
Company
LOGO
Octal to Decimal

(362)8
= 3´ 8 + 6 ´ 8 + 2 ´ 8
2 1 0

= 192 + 48 + 2
= (242)10

www.company.com
Company
LOGO
Hexadecimal to
Decimal

(19B)16
= 1´ 16 + 9 ´ 16 + 11´ 16
2 1 0

= 256 + 144 + 11
= (411)10

www.company.com
Company
LOGO
Try These…..

1. Convert (1001100)2 to decimal.


2. Convert (75)8 to decimal.
3. Convert (23E)16 to decimal.

www.company.com
Company
LOGO

Decimal
Conversions
From decimal to binary, octal and
hexadecimal using Repeated Division

www.company.com
Company
LOGO
Decimal to Binary

LSB
50 2 0
25 2 1
12 2 0
6 2 0
3 2 1
1 1
MSB
= 1 1 0 0 1 0 2

www.company.com
Company
LOGO
Decimal to Octal

50 8 2
6 6

= 6 2 8

www.company.com
Company
LOGO
Decimal to
Hexadecimal

50 16 2
3 3

= 3 2 16

www.company.com
Company
LOGO
Try this

• Convert the decimal number 83 into


the following number systems:
a) Binary
b) Octal
c) Hexadecimal

www.company.com
Company
LOGO

Binary
Conversions
Converting Binary number to Octal or
Hexadecimal by grouping the number of
bits.

www.company.com
Company
LOGO
Binary to Octal

111110102 = 011 111 010

3 7 2 = 3728

www.company.com
Company
LOGO
Binary to Hexadecimal

10101011112 = 0010 1010 1111

2 A F = 2AF16

www.company.com
Company
LOGO
Try these

• Convert the following binary numbers


into octal and hexadecimal
a) 11100111101
b) 100011001111

www.company.com
Company
LOGO
Octal to Binary

Octal 0 1 2 3 4 5 6 7

Binary 000 001 010 011 100 101 110 111

3 7 2 = 3728

011 111 010 = 111110102

www.company.com
Company
LOGO
Hexadecimal to Binary

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

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

2 A F = 2AF16

0010 1010 1111 = 10101011112

www.company.com
Company
LOGO
Try these

• Convert the following numbers into


binary
a) (3671)8
b) (ABCD)16

www.company.com
Company
LOGO

Arithmetic
Operations of the
Number Systems
How we perform arithmetic operations for
Binary, Octal and Hexadecimal Numbers.

www.company.com
Company
LOGO
Binary Addition

• Four basic rules:


0+0=0 Sum of 0 with a carry of 0
0+1=1 Sum of 1 with a carry of 0
1+0=1 Sum of 1 with a carry of 0
1 + 1 = 10 Sum of 0 with a carry of 1

Carry Carry
1 1
e.g: 11+1 0 1 1
+ 0 0 1
1 0 0

www.company.com
Company
LOGO
Binary Subtraction

• Four basic rules:


0-0=0
1-1=0
1-0=1
10 - 1 = 1 0 - 1 with a borrow of 1

Borrow
0 1
e.g: 101-011 1 0 1
- 0 1 1
0 1 0

www.company.com
Company
LOGO
Binary Multiplication

• Four basic rules:


0x0=0
0x1=0
1x0=0
1x1=1

e.g: 101x111 1 1 1
x 1 0 1
1 1 1
Partial
0 0 0
products
+ 1 1 1
1 0 0 0 1 1

www.company.com
Company
LOGO
Binary division

• Follows the same procedure as


division in decimal.

e.g: 110/11 1 0
1 1 1 1 0
1 1
0 0 0

www.company.com
Company
LOGO
Octal Addition

• Value of (1)8 carry is equivalent to (8)10

Carry Carry
e.g: (165)8+(143)8 1 1
1 6 5
+ 1 4 3
3 3 0

www.company.com
Company
LOGO
Octal Subtraction

• Value of (1)8 borrow is equivalent to


(8)10.

Borrow
e.g: (137)8-(64)8 0 1
1 3 7
- 0 6 4
0 5 3

www.company.com
Company
LOGO
Hexadecimal Addition

• Value of (1)16 carry is equivalent to


(16)10

Carry
e.g: (A10)16+(1F2)16 1
A 1 0
+ 1 F 2
C 0 2

www.company.com
Company
LOGO
Hexadecimal
Subtraction

• Value of (1)16 borrow is equivalent to


(16)10.

Borrow
e.g: (137)16-(B4)16 0 1
1 3 7
- 0 B 4
0 8 3

www.company.com
Company
LOGO

www.company.com
Company
LOGO

Numbering Code
BCD, Gray Code, Alphanumeric Code

www.company.com
Company
LOGO
Code and Encode

• Code: a special group of symbols.


• Encode: Representing numbers, letters
or words into a code.

Numbers,
letters or Encode Code
words

www.company.com
Company
LOGO
Binary-Coded-Decimal
(BCD) Code

• BCD: coding each digit of a decimal


number into its binary equivalent.
• Four bits represent one decimal digit.
• Codes available: 0000 – 1001.
• Provide easy conversion from decimal
for a digital hardware.
2 1 9 6

0010 0001 1001 0110

www.company.com
Company
LOGO
BCD Code

Do you know why?

1000 1111 is not a BCD

www.company.com
Company
LOGO
BCD Code

• Converting a BCD code to its decimal


equivalent:
1) Break the BCD into 4-bit groups, starting
from LSB.
2) Replace each 4-bit group into its
equivalent decimal.

www.company.com
Decimal
Company Binary Octal Hex BCD
LOGO
0 0000 0 0 0000
1 0001 1 1 0001
2 0010 2 2 0010
3 0011 3 3 0011
4 0100 4 4 0100
5 0101 5 5 0101
6 0110 6 6 0110
7 0111 7 7 0111
8 1000 10 8 1000
9 1001 11 9 1001
10 1010 12 A 0001 0000
11 1011 13 B 0001 0001
12 1100 14 C 0001 0010
13 1101 15 D 0001 0011
14 1110 16 E 0001 0100
15 1111 17 F 0001 0101
www.company.com
Company
LOGO
BCD Code

Binary BCD
• number system • not a number system

• The decimal system with each


• A straight binary code digit encoded in its binary
takes the complete equivalent
decimal number and
represent it in binary • Convert each decimal digit to
– E.g.:156 binary individually

• Advantage of BCD code:


– Relative ease of converting to and
from decimal
– Only 4-bits code group need to be
remembered

www.company.com
Company
LOGO
BCD Code

Decimal Binary

0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

www.company.com
Company
LOGO
Try these…

• Convert the number 86310 to BCD.


• Convert the following BCD code into
decimal number: 0110100000111001

www.company.com
Company
LOGO
Gray Code

• Developed as a way to represent a


sequence of numbers.
• Only one bit changes between two
successive numbers in the sequence.

www.company.com
Company
LOGO
Gray Code
DECIMAL BINARY GRAY CODE
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
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
www.company.com
Company
LOGO
Gray Code Conversion

Binary to Gray Gray to Binary

www.company.com
Company
LOGO
Try this..

• The following is a counting sequence


of a 5-bit binary numbers:
– 00111
– 01000
– 01001
– 01010
• Convert those binary numbers into
gray code.

www.company.com
Company
LOGO
Gray Code Application
An eight-position,
three-bit shaft
encoder

These devices produce a binary


value that represents the position
of a rotating mechanical shaft.

www.company.com
Company
LOGO
Alphanumeric Codes

• Represent characters and functions


found on a computer keyboard.
• ASCII –American Standard Code for
Information Interchange.
– 7-bit code: 128 possible codes.
– E.g.: 1001000 1000101 1001100 1010000
– Hex = 48 45 4C 50
– Character represented = H E L P

www.company.com
Company
LOGO
ASCII – American Standard Code
for Information Interchange

See the entire table in textbook.

www.company.com
Company
LOGO
Alphanumeric Codes

• EBCDIC – Extended Binary Coded


Decimal Interchange Code.
– 8-bit character encoding
Character or ASCII-8 Binary EBCDIC Binary
Number
A 01000001 11000001
E 01000101 11000101
Z 01011010 11101001
0 00110000 11110000
1 00110001 11110001
5 00110101 11110101
www.company.com
Company
LOGO

Signed Number
Handling positive and negative numbers of
binary numbers.

www.company.com
Company
LOGO
Representation of
Signed Numbers

• Signed binary number: consists of 2


information:
– Sign (+ve of –ve)
– Magnitude (the value)
• 3 forms:
– Sign-magnitude (least used).
– 1’s complement.
– 2’s complement (most important).

www.company.com
Company
LOGO
Sign-Magnitude

• The MSB indicates the sign:


– 0: a positive number
– 1: a negative number
• The remaining bits are the magnitude
bits.
• Eg: Express -25 in an 8-bit sign-
magnitude binary number.
– 2510 = 00011001
– -2510 = 10011001

www.company.com
Company
LOGO
Sign-magnitude

0 0 1 0 1 1 0 0
Sign bit (+)
Magnitude = 4410

1 0 1 0 1 1 0 0
Sign bit (-)
Magnitude = -4410

www.company.com
Company
LOGO
1’s complement

• +ve no.: same as +ve sign-magnitude.


• -ve no.: the 1’s complement of the
corresponding +ve number.
– Changing each of the bit value.
• 01
• 10

0 0 1 0 1 1 0 0

1 1 0 1 0 0 1 1

www.company.com
Company
LOGO
1’s complement

+Ve number 0 0 1 0 1 1 0 0 +4410

-Ve number 1 1 0 1 0 0 1 1 -4410

www.company.com
Company
LOGO
2’s complement

• +ve no.: same as +ve sign-magnitude.


• -ve no.: 2’s complement of the
corresponding +ve number.
– Obtained by adding 1 to the 1’s
complement of the corresponding number.

www.company.com
Company
LOGO
2’s complement

A
Binary number 0 0 1 0 1 1 0 0
1's complement form 1 1 0 1 0 0 1 1 B
+1
2's complement form 1 1 0 1 0 1 0 0

+Ve number 0 0 1 0 1 1 0 0 +4410

-Ve number 1 1 0 1 0 1 0 0 -4410

www.company.com
Company
LOGO
Signed Numbers

www.company.com
Company
LOGO
Arithmetic Operations with Signed Numbers

Using the signed number notation with negative


numbers in 2’s complement form simplifies
addition and subtraction of signed numbers.
Rules for addition: Add the two signed numbers.
Discard any final carries. The result is in signed
form.

Examples:
00011110 = +30 00001110 = +14 11111111 = -1
00001111 = +15 11101111 = -17 11111000 = -8
00101101= +45 11111101 = -3 1 11110111 = -9
Discard carry

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All
Rights Reserved www.company.com
Company
LOGO
Arithmetic Operations with Signed Numbers

Rules for subtraction: 2’s complement the


subtrahend and add the numbers. Discard any final
carries. The result is in signed form.
Repeat the examples done previously, but
subtract:
00011110 (+30) 00001110 (+14) 11111111 (-1)
- 00001111 –(+15) - 11101111 –(-17) - 11111000 –(-8)
2’s complement subtrahend and
add:
00011110 = +30 00001110 = +14 11111111 = -1
11110001 = -15 00010001 = +17 00001000 = +8
1 00001111 = +15 00011111 = +31 1 00000111 = +7
Discard carry Discard carry

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All
Rights Reserved www.company.com
Company
LOGO
Any question?

www.company.com

Potrebbero piacerti anche