Vous êtes sur la page 1sur 22

Chapter 2

Number Systems,
Operations, and Codes

By Taweesak Reungpeerakul

241-208 CH2 1
Contents
 Decimal and Binary Numbers
 Decimal-binary Conversion
 Binary Arithmetic
 Arithmetic Operations
 Hexadecimal and Octal Numbers
 Binary Coded Decimal (BCD)
 Digital Codes and Parity
241-208 CH2 2
2.1 Decimal Numbers
 Decimal Numbers: each of ten digits (0-9)

Dn D3D2D1D0.d1d2d3
Dn*10 n

D3*10 3 d3*10 -3

D2*10 2 d2*10 -2

1 d1*10 -1
D1*10

D0*10 0

241-208 CH2 3
2.2 Binary Numbers
 Binary Numbers: each of 2 digits (0,1) called bits
 Largest decimal number = 2n-1; n is # of bits
 Binary-to-Decimal Conversion
Bn B3B2B1B0.b1b2b3
(Bn*2 n) +
(B3*2 3) + b3*2 -3

(B2*2 2) + (b2*2 -2) +

(B1*2 1) + (b1*2 -1) +

(B0*2 0)+
241-208 CH2 4
Examples
 Example of Largest Decimal Number
B3B2B1B0  Binary 4 bits  24-1 = 15
 Example of Binary-to-Decimal Conversion
Binary: 101.011
 (1*22) + (0*21) + (1*20) + (0*2-1) + (1*2-2) + (1*2-3)
Decimal = 4 + 1 + 0.25 + 0.125
= 5.375
Question: find largest decimal number of
B3B2B1B0.b1b2

241-208 CH2 5
2.3 Decimal-to-Binary Conversion
 Converting Decimal (no Fraction) to
Binary
Ex: 11
11 / 2 = 5 R 1
5 /2 = 2 R 1
2/2 =1 R0

Binary = 1 0 1 1

241-208 CH2 6
2.3 Decimal-to-Binary Conversion
(cont.)
 Converting Decimal Fraction to Binary
Ex: 0.375 Carry
0.375*2 = 0.75 0
0.75*2 = 1.50 1
0.50*2 = 1.00 1

Binary = . 0 1 1

Question: convert 12.3125 to binary


Answer: 1100.0101
241-208 CH2 7
2.4 Binary Arithmetic
 Addition  Multiplication
c 0*0 = 0
0+0 = 0 0*1 = 0
0+1 = 1 1*0 = 0
1+0 = 1 1*1 = 1
1+1 = 10
 Subtraction
c
0-0 = 0
1-1 = 0
1-0 = 1
10-1 = 1

241-208 CH2 8
2.5 1s & 2s Complements
 1s Complement: change all 0s to 1s
and all 1s to 0s
Example: 01001  10110

 2s Complement: (1s comp. +1)


Example: 01001  10110+1 = 10111

241-208 CH2 9
2.6 Signed Numbers
 The left most bit in a signed binary
number is the sign bit.
 Sign-Magnitude System:0 is for positive,
1 is for negative
 25 00011001; -25  10011001
 1s Complement System
 25 00011001; -25  11100110
 2s Complement System
 25 00011001; -25  11100111
241-208 CH2 10
2.7 Arithmetic Operations
 Addition + Operation +
 Subtraction + Operation
 Multiplication - Operation +
 Division - Operation
Overflow Condition

241-208 CH2 11
2.8 Hexadecimal Numbers
 The hexadecimal system has a base of
sixteen; 0-9 & A-F
 One hexadecimal bit: 0-F
 Two hexadecimal bits: 00-FF
 Hexadecimal Conversion
 Bin  Hex and Hex  Bin
 Hex  Dec and Dec  Hex

241-208 CH2 12
Hex Conversion
 Bin  Hex and Hex  Bin  Hex  Dec and Dec  Hex
Ex#1: 0011101000001110  ???16 Ex#3: CF16  ???10
0011 1010 0000 1110 Step1: Hex  Bin
 3 A 0 E CF16  11001111
Ans: 0011101000001110  3A0E16 Step2: Bin Dec
11001111  20710
Ex#2: 10CF16  ???2 (Or use weights of hex number)
1 0 C F
0001 0000 1100 1111 Ex#4: 20710  ???16
Ans: 10CF16  0001000011001111 207 /16 = 12.9375  0.9375*16 = F
12 /16 = 0.75  0.75*16 = C
Ans: 20710  CF16

241-208 CH2 13
Hex Addition & Subtraction
 Hex Addition  Hex Subtraction
Ex#1: CD + 1516 = ? Ex#3: CD - 1516 = ?
CD + -1516  1110 1011 = EB
15 CD +
E2 Ans: E2 EB
1B8 Ans: B8
Ex#2: AB + 5516 = ?
AB + Ex#4: AB - 0C = ?
55 -0C  1111 0100 = F4
100 Ans: 10016 AB +
F4
19F Ans: 9F
241-208 CH2 14
2.9 Octal Numbers
 The octal system is composed of eight
digits; 0-7
 One octal bit: 0-7
 Two octal bits: 00-77
 Octal Conversion
 Bin  Oct and Oct  Bin
 Oct  Dec and Dec  Oct

241-208 CH2 15
Oct Conversion
 Bin  Oct and Oct  Bin  Oct  Dec and Dec  Oct
Ex#1: 011101001111  ???8 Ex#3: 458  ???10
011 101 001 111 Step1: Oct  Bin
 3 5 1 7 458  100101
Ans: 011101001111  35178 Step2: Bin Dec
100101  3710
Ex#2: 5028  ???2 (Or use weights of hex number)
5 0 2
101 000 010 Ex#4: 3710  ???8
Ans: 5028  101000010 37 /8 = 4.625  0.625*8 = 5
4 /8 = 0.500  0.500*8 = 4
Ans: 3710  458

241-208 CH2 16
2.10 Binary Coded Decimal (BCD)
 BCD means that each decimal digit, 0-9,
is represented by a binary code of 4 bits.
 Another name is 8421 code.
 Ex#1: 70110  BCD 7 0 1
0111 0000 0001
 Ex#2: BCD Addition; 1000 + 0101 =?

1000  8 8+
0101  5 5
13  00010011 Ans:
241-208 CH2 1
2.11 Digital Codes and Parity
 Gray Code: unweighted & not an
arithmetic code
Decimal Binary Gray
0 000 000
1 001 001
2 010 011
3 011 010
4 100 110
5 101 111
6 110 101
7 111 100 Question: Adv?
241-208 CH2 2
The Advantage of Gray Code
 The gray code exhibits only one bit
change from one code number to the
next.

241-208 CH2 3
Gray and Binary conversion
 Bin  Gray  Gray  BIN
EX: 0 1 1 0  ??? EX: 0 1 1 0  ???
0110 0110
+ +

0 1 0 1 010 0

241-208 CH2 4
Parity Method for Error Detection
 A parity bit is attached to a group of
bits to make the total number of 1s in a
group always even or always odd.
BCD Even Parity Odd Parity
0000 0 1
0101 0 1
0111 1 0
1000 1 0
241-208 CH2 5
Error Detection
Example (Even parity of error detection)
A group of data: 01011100
Even parity: 0
Sender Receiver Result
001011100 --case I: 001011100 correct
Parity bit
case II: 001001100 incorrect
case III: 001001110 aliasing

241-208 CH2 6

Vous aimerez peut-être aussi