Lecture2-Number Systems and Codes
Lecture2-Number Systems and Codes
Lecture2-Number Systems and Codes
and Codes
• Objectives
– Number systems (Decimal, Binary,Octal
Hexadecimal)
– Conversions
– Arithmetic
– BCD
– Gray Code
– ASCII
– Error checking
• Reading assignments
– Chapter2 p46 - p97
Place Value System
…25 24 23 22 21 20.
• For fractional binary numbers, the column weights are
negative powers of two that decrease from left to right:
2 49 Quotient
2 24 ……..…1 LSB
Least Significant Bit
2 12 ……..…0
2 6 ……..…0
2 3 ……..…0
2 1 ……..…1 MSB
0 ……..…1 Most Significant Bit
Binary Addition
The rules for binary addition are
0+0=0 Sum = 0, carry = 0
0+1=1 Sum = 1, carry = 0
1+0=1 Sum = 1, carry = 0
1 + 1 = 10 Sum = 0, carry = 1
When an input carry = 1 due to a previous result, the rules
are
1 + 0 + 0 = 01 Sum = 1, carry = 0
1 + 0 + 1 = 10 Sum = 0, carry = 1
1 + 1 + 0 = 10 Sum = 0, carry = 1
1 + 1 + 1 = 11 Sum = 1, carry = 1
Binary Addition
Add the binary numbers 00111 and 10101 and show
the equivalent decimal addition.
0111
00111 7
10101 21
11100 = 28
Binary Subtraction
The rules for binary subtraction are
0-0=0
1-1=0
1-0=1
10 - 1 = 1 with a borrow of 1
Subtract the binary number 00111 from 10101 and
show the equivalent decimal subtraction.
111
10101
/ / / 21
00111 7
01110 = 14
1’s Complement
The 1’s complement of a binary number is just the inverse
of the digits. To form the 1’s complement, change all 0’s to
1’s and all 1’s to 0’s.
For example, the 1’s complement of 11001010 is
00110101
In digital circuits, the 1’s complement is formed by using
inverters:
1 1 0 0 1 0 1 0
0 0 1 1 0 1 0 1
2’s Complement
The 2’s complement of a binary number is found by
adding 1 to the LSB of the 1’s complement.
Recall that the 1’s complement of 11001010 is
00110101 (1’s complement)
To form the 2’s complement, add 1: +1
1 1 0 0 1 0 1 0 00110110 (2’s complement)
1
0 0 1 1 0 1 0 1
Input bits
Carry
Adder
in (add 1)
Output bits (sum)
0 0 1 1 0 1 1 0
Signed Binary Numbers
There are several ways to represent signed binary numbers. In all cases,
the MSB in a signed number is the sign bit, that tells you if the number
is positive or negative.
Computers use a modified 2’s complement for signed numbers.
• Positive numbers are stored in true form (with a 0 for the sign bit)
• Negative numbers are stored in complement form (with a “1” for the
sign bit).
Binary sequence
Gray code sequence
ASCII