Special Powers of 2
210 (1024) is Kilo, denoted "K"
220 (1,048,576) is Mega, denoted "M"
230 (1,073, 741,824)is Giga, denoted "G"
240 (1,099,511,627,776 ) is Tera, denoted “T"
Binary Bit and Group
Definitions
Bit - a single binary digit
Nibble - a group of four bits
Byte - a group of eight bits
Word - depends on processor; 8, 16,
32, or 64 bits
LSB - Least Significant Bit (on the
right)
MSB - Most Significant Bit (on the left)
1’s and 2’s Complements
They are important since they
permit the presentation of negative
numbers.
The method of 2’s complement
arithmetic is commonly used in
computers to handle negative
numbers.
Finding the 1’s complement
Very simple: change each bit in a
number to get the 1’s complement
ex: find 1’s complement of 111001012
Binary 1 1 1 0 0 1 0 1
1’s complement 0 0 0 1 1 0 1 0
Finding the 2’s Complement
Add 1 to the 1’s complement to get the
2’s complement.1’s complement
+1
2’s complement
ex: 10110010 01001101 01001110
Signed Numbers
Digital systems, such as computer,
must be able to handle both positive
and negative numbers.
A signed binary number consists of
both sign and magnitude information.
– The sign indicates whether a number is
positive or negative.
– The magnitude is the value of the
number.
Signed Numbers
There are 3 forms in which signed
integer numbers can be
represented in binary:
– Sign-magnitude (least used)
– 1’s complement
– 2’s complement (most important)
Non-integer and very large or small
numbers can be expressed in
floating-point format.
The Sign Bit
The left-most bit in a signed binary
number is the sign bit.
– It tells you whether the number is positive
(sign bit = 0) or negative (sign bit = 1).
Sign-Magnitude Form
The left-most bit is the sign bit and the
remaining bits are the magnitude bits.
– The magnitude bits are in true binary for
both positive and negative numbers.
ex: the decimal number +25 is expressed as an 8-bit
signed binary number as:
00011001
While the decimal number -25 is expressed as
10011001
Sign-Magnitude Form
“ In the sign-magnitude form, a
negative number has the same
magnitude bits as the
corresponding positive number
but the sign bit is a 1 rather
than a 0. “
1’s Complement Form
Positive numbers in 1’s complement
form are represented the same way as
the positive sign-magnitude.
Negative numbers are the 1’s
complements of the corresponding
positive numbers.
ex: the decimal number +25 is expressed as:
00011001
While the decimal number -25 is expressed as
11100110
1’s Complement Form
“ In the 1’s complement form, a
negative number is the 1’s
complement of the corresponding
positive number. “
2’s Complement Form
Positive numbers in 2’s complement form are
represented the same way as the positive sign-
magnitude and 1’s complement form.
Negative numbers are the 2’s complements of the
corresponding positive numbers.
ex: the decimal number +25 is expressed as:
00011001
While the decimal number -25 is expressed as
11100111
2’s Complement Form
“ In the 2’s complement form, a
negative number is the 2’s
complement of the corresponding
positive number. “
Decimal Value of Signed Numbers
Sign-magnitude:
– Both positive and negative numbers
are determined by summing the
weights in all the magnitude bit
positions where these are 1s and
ignoring those positions where there
are 0s.
– The sign is determined by examination
of the sign bit.
Decimal Value of Signed Numbers
Sign-magnitude (by example)
ex: decimal values of these numbers (expressed in sign-
magnitude)
1) 10010101 2) 01110111
1) 10010101 2) 01110111
magnitude magnitude
26 25 24 23 22 21 20 26 25 24 23 22 21 20
0 0 1 0 1 0 1 1 1 1 0 1 1 1
= 16+4+1 = 21 = 64+32+16+4+2+1 = 119
sign sign
= 1 negative = 0 positive
Hence: 10010101 = -21 Hence: 01110111 = 119
Decimal Value of Signed Numbers
1’s complement:
– Positive – determined by summing the
weights in all bit positions where there
are 1s and ignoring those positions
where there are 0s.
– Negative – determined by assigning a
negative value to the weight of the
sign bit, summing all the weights
where there are 1’s, and adding 1 to
the result.
Decimal Value of Signed Numbers
1’s complement (by example)
ex: decimal values of these numbers (expressed in 1’s
complement)
1) 00010111 2) 11101000
1) 00010111 2) 11101000
-27 26 25 24 23 22 21 20 -27 26 25 24 23 22 21 20
0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 0
= 16+4+2+1 = +23 = (-128)+64+32+8 = -24
+1
Hence: 00010111 = +23 Hence: 11101000 = -23
Decimal Value of Signed Numbers
2’s complement:
– Positive – determined by summing the
weights in all bit positions where there
are 1s and ignoring those positions
where there are 0s.
– Negative – the weight of the sign bit in
a negative number is given a negative
value.
Decimal Value of Signed Numbers
2’s complement (by example)
ex: decimal values of these numbers (expressed in 2’s
complement)
1) 01010110 2) 10101010
1) 01010110 2) 10101010
-27 26 25 24 23 22 21 20 -27 26 25 24 23 22 21 20
0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0
= 64+16+4+2 = +86 = (-128)+32+8+2 = -86
Hence: 01010110 = +86 Hence: 10101010 = -86
Range of Signed Integer Numbers
The range of magnitude of a binary
number depends on the number of
bits (n).
Total combinations = 2n
– 8 bits = 256 different numbers
– 16 bits = 65,536 different numbers
– 32 bits = 4,294,967,296 different
numbers
Range of Signed Integer Numbers
For 2’s complement signed numbers:
– Range = -(2n-1) to +(2n-1-1)
– where there is one sign bit and n-1 magnitude
ex:
Negative Positive
Boundary Boundary
4 bits -(23) = -8 (23-1) = +7
8 bits -(27) = -128 (27-1) = +127
16 bits -(215) = (215-1) =
-32,768 +32767
Arithmetic Operations with
Signed Numbers
Because the 2’s complement form
for representing signed numbers is
the most widely used in computer
systems. We’ll limit to 2’s
complement arithmetic on:
– Addition
– Subtraction
– Multiplication
– Division
Addition
4 cases that can occur when 2
signed numbers are added:
– Both numbers positive
– Positive number with magnitude larger
than negative number
– Negative number with magnitude
larger than positive number
– Both numbers negative
Addition
Both numbers positive:
ex: 00000111 7
+00000100 +4
00001011 11
The sum is positive and is therefore
in true (uncomplemented) binary.
Addition
Positive number with magnitude larger
than negative number:
ex: 00001111 15
+11111010 + -6
Discard 1 00001001 9
carry
The final carry bit is discarded. The
sum is positive and is therefore in true
(uncomplemented) binary.
Addition
Negative number with magnitude larger
than positive number:
ex: 00010000 16
+11101000 + -24
11111000 -8
The sum is negative and therefore in
2’s complement form.
Addition
Both numbers negative:
ex: 11111011 -5
+11110111 + -9
Discard 1 11110010 -14
carry
The final carry bit is discarded. The
sum is negative and therefore in 2’s
complement form.
Addition
Remark:
– The negative numbers are stored in
2’s complement form so, as you can
see, the addition process is very
simple: Add the two numbers and
discard any final carry bit.
Addition
Overflow condition:
– When two numbers are added
and the number of bits
required to represent the sum
exceeds the number of bits in ex: 01111101 125
the two numbers, an overflow +00111010
10110111
+ 58
183
results as indicated by an
incorrect sign bit.
– An overflow can occur only Magnitude
incorrect
when both numbers are + or -.
Sign
incorrect
Addition
Numbers are added two at a time:
– Computer add strings of numbers two
numbers at a time.
ex: add the signed numbers: 01000100, 00011011, 00001110, and
00010010
68 01000100
+ 27 + 00011011 Add 1st two numbers
95 01011111 1st sum
+ 14 + 00001110 Add 3rd number
109 01101101 2nd sum
+ 18 + 00010010 Add 4th number
127 01111111 Final sum
Subtraction
Subtraction is a special case of
addition.
– Subtraction is addition with the sign of
the subtrahend changed.
– The result of a subtraction is called
the difference.
The sign of a positive or negative
binary is changed by taking it’s 2’s
complement.
Subtraction
Since subtraction is simply an
addition with the sign of the
subtrahend changed, the process is
stated as follows:
– To subtract two signed numbers, take
the 2’s complement of the subtrahend
and add. Discard any final carry.
Subtraction
ex: Perform each of the following subtraction of the signed
numbers:
(a) 00001000 – 00000011 (b) 00001100 - 11110111
(c) 11100111 – 00010011 (d) 10001000 - 11100010
(a) 00001000 8 (b) 00001100 12
+11111101 + -3 +00001001 + 9
100000101 5 00010101 21
(c) 11100111 -25 (d) 10001000 -120
+11101101 + -19 +00011110 + 30
111010100 -44 10100110 -90
Your Next reading Assignment
Read the multiplication and division
procedures. We shall have an oral
quize on this topic in the next
lecture
Binary Coded Decimal (BCD)
Would it be easy for you if you can
replace a decimal number with an
individual binary code?
– Such as 00011001 = 1910
The 8421 code is a type of BCD to
do that.
BCD code provides an excellent
interface to binary systems:
– Keypad inputs
– Digital readouts
Binary Coded Decimal
Decimal
0 1 2 3 4 5 6 7 8 9
Digit
BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
Note: 1010, 1011, 1100, 1101, 1110, and 1111 are INVALID CODE!
Let’s crack these…
ex1: dec-to-BCD ex2: BCD-to-dec
(a) 35 (a) 10000110
(b) 98 (b) 001101010001
(c) 170 (c) 1001010001110000
(d) 2469
Warning: Conversion or
Coding?
Do NOT mix up conversion of a
decimal number to a binary number
with coding a decimal number with a
BINARY CODE.
1310 = 11012 (This is
conversion)
13 0001|0011 (This is
coding)
BCD Addition
BCD is a numerical code and can be used in
arithmetic operations. Here is how to add two
BCD numbers:
– Add the two BCD numbers, using the rules for
basic binary addition.
– If a 4-bit sum is equal to or less than 9, it is a valid
BCD number.
– If a 4-bit sum > 9, or if a carry out of the 4-bit
group is generated it is an invalid result. Add 6
(0110) to a 4-bit sum in order to skip the six the
invalid states and return the code to 8421. If a
carry results when 6 is added, simply add the
carry to the next 4-bit group.
Alphanumeric Codes
Represent numbers and alphabetic
characters.
– Also represent other characters such
as symbols and various instructions
necessary for conveying information.
The ASCII is the most common
alphanumeric code.
– ASCII = American Standard Code for
Information Interchange
ASCII
ASCII has 128 characters and
symbols represented by a 7-bit
binary code.
– It can be considered an 8-bit code with
the MSB always 0. (00h-7Fh)
• 00h-1Fh (the first 32) – control characters
• 20h-7Fh – graphics symbols (can be
printed or displayed)
ASCII
Table
http://ascii-table.com/img/table.gif
Extended ASCII
There are an additional 128
characters that were adopted by
IBM for use in their PCs. It’s
popular and is used in applications
other than PCs unofficial
standard.
– The extended ASCII characters are
represented by an 8-bit code series
from 80h-FFh
Extended ASCII
Table
http://ascii-table.com/img/table-pc.gif
UNICODE
UNICODE extends ASCII to 65,536
universal characters codes
– For encoding characters in world
languages
– Available in many modern applications
– 2 byte (16-bit) code words
– See Reading Supplement – Unicode on
the Companion Website
http://www.prenhall.com/mano
Read and try to Understand the
Greys code from your Text book.
We shall have a discussion on it in
the next class