Binary Arithmetic
Binary Addition
Binary Subtraction
Binary Multiplication
Binary Division
Binary Addition
Four Basic rules for binary addition
1st digit 2nd digit Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
◼ Addition of multiple binary numbers
Binary Addition
Carry 1 10 1
1st Number 1 0 1 1
2nd Number 1 1 0
3rd Number 1 0 0 0
4th Number 1 1
Result 1 1 1 0 0
Binary Subtraction
Four Basic rules for binary subtraction
1st digit 2nd digit Difference Borrow
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
Binary Subtraction
Borrow 1
1st Number 1 0 1 1
2nd Number 1 1 0
Result 1 0 1
Binary Multiplication
Four Basic rules for binary multiplication
1st digit 2nd digit Product
0 0 0
0 1 0
1 0 0
1 1 1
◼ Example of Binary Multiplication
Binary Multiplication
1101 (13)
x 101 (5)
1st product term 1101
2nd product term 0000
3rd product term 1101
Product 1000001 (65)
Multiplication by shifting left
Decimal 29 shifted left by one digit
290
Shift left 1 digit is multiply by 10
Binary 111012 (29) shifted left by one bit
1110102 (58)
Shift left 1 bit is multiply by 2
Binary Division
10
101 | 1101
101
011
000
11
Division by shifting right
Decimal 29 shifted right by one digit
2.9
Shift left 1 digit is divide by 10
Binary 111012 (29) shifted left by one bit
1110.12 (14.5)
Shift left 1 bit is divide by 2
Signed and Unsigned Numbers
Unsigned Binary Numbers
Signed Binary Numbers
Most significant bit represents sign
0 represents a positive number
1 represents a negative number
2’s Complement form
1’s complement form
2’s complement form
Binary number 01101 (13)
1’s complement 10010
+ 1
2’s complement 10011 (-13)
Alternate Representations
BCD Code
BCD Addition
Gray Code
Alternate Representations
BCD (Binary Coded Decimal) Code
Decimal BCD Decimal BCD
0 0000 5 0101
1 0001 6 0110
2 0010 7 0111
3 0011 8 1000
4 0100 9 1001
BCD Addition
Multi-digit BCD numbers can be added together
23 0010 0011
45 0100 0101
68 0110 1000
23 0010 0011
48 0100 1000
71 0110 1011
1011 is illegal BCD number
BCD Addition
Add a 0110 (6) to an invalid BCD number
Carry added to the most significant BCD digit
23 0010 0011
48 0100 1000
71 0110 1011
0110
0111 0001
Gray Code
A Gray code is an encoding of numbers so that adjacent numbers have a
single digit differing by 1. The term Gray code is often used to refer to a
"reflected" code, or more specifically still, the binary reflected Gray code
Binary Code more than 1 bit change
Electromechanical applications of digital systems restrict bit change to 1
Shaft encoders
Braking Systems
Gray Code
Decimal Gray Binary
0 0000 0000
1 0001 0001
2 0011 0010
3 0010 0011
4 0110 0100
5 0111 0101
6 0101 0110
7 0100 0111
Binary to Gray
1. The most significant bit (left-most) in the binary code is the same as
corresponding in the Gray code.
2. Add each binary code bit generated to the Gray code bit in the next
adjancent position.Discard carries. For exapmle
1 1 0 1 1 Gray
1 0 0 1 0 Binary
Binary to gray
Bray Code to Binary
ASCII Character Codes and Properties 23
ASCII, stands for American Standard Code for Information Interchange.
It is a 7-bit character code where each individual bit represents a unique
character.
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).
24
American Standard Code for Information Interchange (ASCII) Character
Code
25
ASCII Character Code
26
Error-Detecting Code
To detect errors in data communication and processing, an eighth bit is sometimes
added to the ASCII character to indicate its parity.
A parity bit is an extra bit included with a message to make the total number of 1's
either even or odd.
Example:
Consider the following two characters and their even and odd parity:
27
Error-Detecting Code
Redundancy (e.g. extra information), in the form of extra bits, can
be incorporated into binary code words to detect and correct
errors.
A simple form of redundancy is parity, an extra bit appended onto
the code word to make the number of 1’s odd or even. Parity can
detect all single-bit errors and some multiple-bit errors.
A code word has even parity if the number of 1’s in the code word
is even.
A code word has odd parity if the number of 1’s in the code word is odd.
Example:
Message A: 10001001 1 (even parity)
Message B: 10001001 0 (odd parity)