Chapter 2
Chapter 2
Number System,
Operation and Codes
CHAPTER OUTLINE
• Decimal Numbers
• Binary Numbers
• Decimal-to-Binary Conversion
• Binary Arithmetic
• Complements of Binary Numbers
• Signed Numbers
• Arithmetic Operations with Signed Numbers
• Hexadecimal Numbers
• Octal Numbers
• Binary Coded Decimal (BCD)
• Digital Codes
• Error Codes
DECIMAL NUMBERS
BINARY NUMBERS
BINARY NUMBERS
A SIMPLE BINARY COUNTING
APPLICATION.
THE WEIGHTING STRUCTURE OF
BINARY NUMBERS
Binary to Decimal Conversion
DECIMAL TO BINARY CONVERSION
DECIMAL TO BINARY CONVERSION
DECIMAL TO BINARY CONVERSION
Binary to Decimal Conversion
1. 2267 2. 32768
Decimal to Binary Conversion
10.111 = 2.875
RULES OF BINARY ADDITION
11 + 11 = 110 (3+3=6)
100+ 10 = 110 (4+2=6)
111+11 = 1010 ( 7+3=10)
110+100=1010 (6+4=10)
Note: (1+1+1 = 11)
RULES OF BINARY SUBTRACTION
11-01 = 10 (3-1=2)
11-10 = 01 ( 3-2=1)
101 -011 = 010 (5-3=2)
RULES OF BINARY MULTIPLICATION
Rules of binary Division
Division in binary follows the same procedure as division in decimal.
The equivalent decimal divisions are also given.
Examples
1’ s and 2’s Complements of Binary Numbers
to the minuend.
2’s Complement :
The decimal number -25 is expressed as the 2' s complement of + 25 (0001100 I ) as
11100111
Examples (Signed Numbers)
Examples (Signed Numbers)
Express + 19 and - 19 in sign-magnitude, I's complement, and 2's
complement.
The Decimal Value of Signed Numbers
01110111 = +119 10
The Decimal Value of Signed Numbers
1’s Complement
The Decimal Value of Signed Numbers
1’s Complement
-20
The Decimal Value of Signed Numbers
2’s Complement
-41
Summary of integer representation
# of Bits Range
--------- -------------------------------------
8 0 255
16 0 65,535
Range of sign-and-magnitude integers
# of Bits Range
---------- -------------------------------------------------------
8 −127 −0 +0 +127
16 −32767 −0 +0 +32767
32 −2,147,483,647 −0 +0 +2,147,483,647
Note:
# of Bits Range
--------- -------------------------------------------------------
8 −128 0 +127
16 −32,768 0 +32,767
32 −2,147,483,648 0 +2,147,483,647
The Decimal Value of Signed Numbers
1’s and 2’s Complement
ADD/SUB : 4 COMBINATIONS
9 (-9)
Positive / Positive Negative / Positive
Positive Answer + 5 Negative Answer + 5
14 -4
9 (-9)
Positive / Negative Negative / Negative
Positive Answer
+ (-5) Negative Answer + (-5)
4 - 14
40
POSITIVE / POSITIVE
COMBINATION
9 ⎯→ 00001001
Positive / Positive
+ 5 ⎯→ + 00000101
Positive Answer
14 ←⎯ 00001110
Both Positive Numbers
Use Straight Binary Addition
41
POSITIVE / NEGATIVE
COMBINATION
9 ⎯→ 00001001
Positive / Negative
Positive Answer + (-5) + 11111011
4 ←⎯ 1]00000100
1-Positive / 1-Negative
8th Bit = 0 : Answer is Positive
Take 2’s Complement Disregard 9th Bit
Of Negative Number (-5)
00000101
↓↓↓↓↓↓↓↓ 2’s
11111010 Complement
Process
+1 42
11111011
NEGATIVE / POSITIVE
COMBINATION
(-9) 11110111
Positive / Negative
+ 5 ⎯→ + 00000101
Negative Answer
- 4 11111100
1-Positive / 1-Negative
8th Bit = 1 : Answer is Negative
Take 2’s Complement Take 2’s Complement to Check Answer
Of Negative Number (-9)
11111100 00001001
2’s ↓↓↓↓↓↓↓↓ ↓↓↓↓↓↓↓↓ 2’s
Complement 00000011 11110110 Complement
Process Process
+1 +1 43
00000100 11110111
NEGATIVE / NEGATIVE
COMBINATION
(-9) ⎯→ 11110111 2’s Complement
Numbers, See
⎯→
Conversion Process
Negative / Negative
Negative Answer + (-5) + 11111011 In Previous Slides
- 14 1]11110010
2-Negative
Take 2’s Complement Of 8th Bit = 1 : Answer is Negative
Disregard 9th Bit
Both Negative Numbers Take 2’s Complement to Check Answer
11110010
2’s ↓↓↓↓↓↓↓↓
Complement 00001101
Process +1 44
00001110
Subtraction (Examples)
Signed Multiplication
Signed Multiplication
Signed Multiplication
The following example shows signed 2's complement representation
can be used to represent negative operands as well as positive ones
in multiplication( using 6bit representation).
Example:
Signed Division
USEFULNESS OF HEX
Hex is often used in a digital system as sort of a “Shorthand” way
to represent string of bits.
When dealing with the large numbers of bits , it is more
convenient and less error to write the binary in hex.
Would you rather check 50 numbers like this one
0110111001100111
or 50 numbers like this one 6E67 ?
Advantage:
Easy conversion
Disadvantage:
BCD required more bits
Example: Decimal Binary BCD
11 1011 0001 0001
ADDITION OF BCD NUMBERS
Addition of BCD numbers
NOTE THAT IN EACH CASE THE SUM IN ANY 4
BIT COLUMN DOES NOT EXCEED 9, AND THE
RESULT ARE INVALID BCD NUMBERS.
Addition of BCD numbers
Addition of BCD numbers
GRAY CODE:
The bits in a binary count sequence, it is clear that there are often several bits
that must change states at the same time. Consider when 3 - bit binary
number for 3 change to 4 : all three bits must change state.
011 ( decimal 3 )
100 ( decimal 4 )
In order to reduce the likelihood of a digital circuit misinterpreting a changing
input , the Gray code has been developed as way to represent a sequence of
numbers.
The unique aspect of the Gray code is that only one bit ever changes between
two successive numbers in sequence.
The Gray code is also known as The Reflected Code
THREE BIT BINARY AND GRAY
CODE EQUIVALENTS
AN APPLICATION
THE CONCEPT OF A 3-BIT SHAFT
BINARY TO GRAY CODE CONVERSION
The codes that represent letters of the alphabet , punctuation marks, and other
special characters as well as numbers are called Alphanumeric Codes.
• 26 lowercase letter
• 26 uppercase letter
• 10 numeric digits
• 7 punctuation marks
• 20 to 40 other characters such as + , / , %, * and so on
AMERICAN STANDARD CODE FOR
INFORMATION INTERCHANGE( ASCII )CODE:
The ASCII code is used for the transfer of alphanumeric information between a
computer and external devices such as printer or another computer.
Example :
The binary string that will be entered into memory when the operator types
if (x >3).
ERROR DETECTION CODES
Examples of the movement of binary data and code :
• The storage of data in and retrieval of data from external memory devices.
Parity Bit:
A parity bit is an extra bit that is attached to a code group that is being
transferred from one location to another. It is made either 0 or 1.
There are two parity methods:
Even Parity method
Odd Parity method
EVEN PARITY METHOD :
If number of 1s in the code group odd then add a parity bit of 1
.
For example:
The receiver will check that the code contain an odd number of 1s (including the parity)
If so, receiver assume that the code has been correctly receive.
Supposed Some noise change code as
The receiver will find that this code has an even number of 1s and error is detected.
There is no way that the receiver can tell which bit is
in error because it does not know what the code is
supposed to be .
The parity method would not work of two bits were in
error .