2 Binary Arithmetic
2 Binary Arithmetic
24
Addition
• Arithmetic operations in digital systems are usually done in binary
• Design of logic circuits for binary arithmetic is much easier than for
decimal
25
Addition
• Binary Addition
26
Addition
• Example: 1101 + 1011
• Answer: 11000
27
Subtraction
• Decimal subtraction
28
Subtraction
• Decimal subtraction
29
Subtraction
• The subtraction table for binary numbers is
•
• and borrow 1 from the next column
•
•
30
Subtraction
• Binary Subtraction
31
Subtraction
• Example: 11101 – 10011
• Answer: 1010
• Example: 10000 – 11
• Answer: 1101
32
Multiplication
• Decimal Multiplication
33
Multiplication
• The multiplication table for binary numbers is
•
•
•
•
34
Multiplication
35
Multiplication
• Example: 1011 * 101
• Answer: 110111
36
Representation of Negative Numbers
Representation of Negative Numbers
• To represent negative integers, a notation for the negative values
is needed
• It is customary to represent the sign with a bit placed in the
leftmost position of the binary number
• The convention is to make the sign bit 0 for positive and 1 for
negative
• The most common methods for representing both positive and
negative numbers are:
• Signed-magnitude
• 2’s complement
• 1’s complement
38
Signed-Magnitude Numbers
• Consider an n-bit sign and magnitude number
bit 0
0 +ve bit 1 bit 2 … bit n-2 bit n-1
1 -ve
• 1 bit for the sign and n-1 bits for the magnitude
• Number in the range to are represented
• Including +0 and -0
46
Addition of 2’s Complement Numbers
1. Addition of two positive numbers, sum
47
Addition of 2’s Complement Numbers
3. Addition of positive and negative numbers (negative number has a
greater magnitude)
48
Addition of 2’s Complement Numbers
5. Addition of two negative number, |sum|
49
Binary Codes for Decimal Numbers
Binary Codes for Decimal Numbers
• Digital systems use signals that have two distinct values and circuit
elements that have two stable states
• There is a direct analogy between binary signals, binary circuit
elements, and binary digits
• However, the input and output equipment generally use decimal
numbers
• Therefore, decimal numbers must be coded in terms of binary signals
51
Binary-Coded Decimal (BCD) Code
• Each decimal digit is replaced by its binary equivalent
52
Binary-Coded Decimal (BCD) Code
• A decimal number in BCD is
the same as its equivalent
binary number only when
the number is between 0
and 9
• The binary combinations
1010 through 1111 are not
used and have no meaning
in BCD
53
Other Decimal Codes
54
Gray Code
• Used in applications in which the
normal sequence of binary numbers
generated by hardware may produce
errors or ambiguity during the
transition from one number to the
next
• In Gray code, only one bit changes its
value during any transition between
two numbers
55
ASCII Code
• American Standard Code for Information Interchange (ASCII) Character
Code
• A popular code used to represent information sent as character-based
data.
• It uses 7-bits to represent:
• 94 Graphic printing characters.
• 34 Non-printing characters.
• Some non-printing characters are used for text format (e.g. BS =
Backspace, CR = carriage return).
• Other non-printing characters are used for record marking and flow
control (e.g. STX and ETX start and end text areas).
56
ASCII Code
57