1
00:00:12,170 --> 00:00:17,400
so now we have discussed about representing
positive integers in our system which is actually
2
00:00:17,400 --> 00:00:25,490
very easy so let us now discuss how to represent
negative integers in our system using zeros
3
00:00:25,490 --> 00:00:34,210
and ones so ah whats the problem what we want
to do is that given a negative integers we
4
00:00:34,210 --> 00:00:42,350
want to assign a binary representation to
it in terms of just in a zeros and ones so
5
00:00:42,350 --> 00:00:49,060
consider a negative integer s assume that
is binary form is x n ah to x one so this
6
00:00:49,060 --> 00:00:56,800
is the least significant bit and x n is the
most significant bit and hence forth we will
7
00:00:56,800 --> 00:01:01,420
actually start counting from one not from
zero so now we can also you know given this
8
00:01:01,420 --> 00:01:06,660
number over here which we are representing
we can also expanded to represent an unsigned
9
00:01:06,660 --> 00:01:10,790
unsigned means without a sign assumed to be
positive number n
10
00:01:10,790 --> 00:01:17,299
so we can interpret this binary sequence here
in two ways one is we can interpret it as
11
00:01:17,299 --> 00:01:26,909
an unsigned number so we will get n or we
can represent it as a number with the sign
12
00:01:26,909 --> 00:01:37,359
and we will get s so the so what we need to
do is we need to create a mapping ah from
13
00:01:37,359 --> 00:01:48,149
the set of all the numbers with a sign which
can include both positive numbers as well
14
00:01:48,149 --> 00:01:53,289
as negative numbers to a set of binary unsigned
numbers called n so ah this mapping would
15
00:01:53,289 --> 00:01:59,780
essentially tell us how to represent a number
be positive or negative using a set of binary
16
00:01:59,780 --> 00:02:05,420
bits so let the set of positive and negative
numbers be called as and let each number irrespective
17
00:02:05,420 --> 00:02:10,420
of its sign positive or negative be map through
a sequence of binary numbers and we can alternatively
18
00:02:10,420 --> 00:02:16,310
interpret this number as a positive number
and lets call this set as n if you find a
19
00:02:16,310 --> 00:02:20,870
mapping will be able to represent both positive
as well as negative numbers using a binary
20
00:02:20,870 --> 00:02:23,590
representation for the positive numbers we
already have some idea from a previous discussion
21
00:02:23,590 --> 00:02:27,209
but a previous discussion does not cover negative
numbers so this needs to be covered over here
22
00:02:27,209 --> 00:02:28,790
so lets now take a look at properties of the
mapping function so preferably you need a
23
00:02:28,790 --> 00:02:33,840
one to one mapping which means that given
a certain signed number it needs to have only
24
00:02:33,840 --> 00:02:38,790
one binary representation so ah also the thing
is that the all the entries in the set s that
25
00:02:38,790 --> 00:02:44,060
we need to map ah should be mapped it should
be easy to perform arithmetic operations on
26
00:02:44,060 --> 00:02:48,400
them such as addition and subtraction and
ah so these all are three main assumptions
27
00:02:48,400 --> 00:02:53,770
so lets look at one of the simplest ah possible
ah ways are doing it see assume an n bit number
28
00:02:53,770 --> 00:02:58,739
system and number system in which we have
n bits ah so n bits basically means that in
29
00:02:58,739 --> 00:03:03,769
our number system we will represent every
number by a sequence of n bits right n binary
30
00:03:03,769 --> 00:03:12,700
bits where they can be from x n to x one every
number will be mapped with n bits so ah we
31
00:03:12,700 --> 00:03:18,280
also want to introduce this function sign
bit u which if u is less than zero if the
32
00:03:18,280 --> 00:03:24,760
number is less than zero this sign bit ah
will return one if u is greater than equal
33
00:03:24,760 --> 00:03:30,720
to zero it will return zero so essentially
the number is positive or zero the sign bit
34
00:03:30,720 --> 00:03:36,934
is zero if the number is negative the sign
bit is one so this is a function that we want
35
00:03:36,934 --> 00:03:39,739
to introduce
so lets first look at a very simple ah kind
36
00:03:39,739 --> 00:03:44,480
of representation called as sign magnitude
base representation so here what we do is
37
00:03:44,480 --> 00:03:54,569
that the way we define the mapping is something
like this that we define a function f u where
38
00:03:54,569 --> 00:04:01,709
u is in a where u can be a negative number
or a positive number so we consider the sign
39
00:04:01,709 --> 00:04:07,510
bit multiply it with two to the power n minus
one and added with the absolute value of u
40
00:04:07,510 --> 00:04:13,750
or alternatively we can think that the absolute
value of u is ah the least significant portion
41
00:04:13,750 --> 00:04:18,220
of the representation and ah the sign bit
which is negative which is one if the number
42
00:04:18,220 --> 00:04:24,150
is negative is the m s b of the representation
so this number system is actually very simple
43
00:04:24,150 --> 00:04:31,260
so lets find ah lets look at an example lets
consider minus five so minus five we first
44
00:04:31,260 --> 00:04:38,650
write take the binary representation of plus
five which is one zero one and its sign bit
45
00:04:38,650 --> 00:04:43,022
is equal to one because a number is negative
so this is the representation that we have
46
00:04:43,022 --> 00:04:47,740
if we consider plus five thats also very easy
we take one zero one and we treat the most
47
00:04:47,740 --> 00:04:51,780
significant bit as zero so what we one thing
that we can immediately see over here is at
48
00:04:51,780 --> 00:04:55,360
this number that we have ah in this representation
a positive number is being represented in
49
00:04:55,360 --> 00:05:01,910
exactly the same way as we had discussed for
a negative number we just add a one before
50
00:05:01,910 --> 00:05:05,570
it
consider one more example minus three so we
51
00:05:05,570 --> 00:05:14,660
first write the representations of plus three
and then we add a one as the m s b digit because
52
00:05:14,660 --> 00:05:19,610
a number is negative so what are the problems
there are two representations for zero so
53
00:05:19,610 --> 00:05:24,750
zero can you know both of them are both of
these are valid representations because the
54
00:05:24,750 --> 00:05:32,210
rest of the bits are all zero and the sign
bit is either zero or one so you know it does
55
00:05:32,210 --> 00:05:36,140
not matter but ah still ah there is a ah the
there is a problem in the sense that you you
56
00:05:36,140 --> 00:05:39,230
are having a positive zero and a negative
zero so addition and subtraction are difficult
57
00:05:39,230 --> 00:05:44,970
we can clearly see if you just regularly add
them as binary numbers then ah there is a
58
00:05:44,970 --> 00:05:53,420
problem so ah the most important takeaway
point is yes we introduced a sign bit the
59
00:05:53,420 --> 00:06:01,770
sign bit did have some advantages no doubt
however ah it introduced more problems than
60
00:06:01,770 --> 00:06:10,890
it could solve for example there are two representations
of zero which is something that we dont want
61
00:06:10,890 --> 00:06:18,160
so now lets look at the ones compliment representation
which is very simple lets first look at the
62
00:06:18,160 --> 00:06:23,700
examples so if you have plus three gets represented
in the same way as other positive number is
63
00:06:23,700 --> 00:06:32,170
zero zero one one if we consider minus three
what we do is that we just invert every single
64
00:06:32,170 --> 00:06:44,420
bit of zero zero one one to get one one zero
zero similarly if we consider plus five we
65
00:06:44,420 --> 00:06:54,480
take the regular unsigned representation of
plus five which is zero one zero one and if
66
00:06:54,480 --> 00:07:02,370
we consider minus five then we what we basically
do is that we invert every single bit of plus
67
00:07:02,370 --> 00:07:10,680
five to get minus five here also ah you will
notice that the notation of the sign bit is
68
00:07:10,680 --> 00:07:22,270
also come in the sense that ah for numbers
that are positive the m s b the most significant
69
00:07:22,270 --> 00:07:27,750
bit is zero and for numbers that are negative
the most significant bit one so ah in a sense
70
00:07:27,750 --> 00:07:32,540
the notation of the sign bit is also come
that positive numbers will have will start
71
00:07:32,540 --> 00:07:36,930
with zero and negative numbers will start
with a one which helps us distinguish between
72
00:07:36,930 --> 00:07:43,600
positive and negative but it does not confer
any more mathematical properties
73
00:07:43,600 --> 00:07:49,820
so lets look at the problems of this representation
the problems of this ah representation are
74
00:07:49,820 --> 00:07:57,720
like this that there are two representations
for zero which is something that we wanted
75
00:07:57,720 --> 00:08:05,150
to avoid so zero zero zero is also zero and
one one one is also zero and this is not in
76
00:08:05,150 --> 00:08:13,330
our best interest in the sense we didnt wanted
it introduces ambiguity in to the number system
77
00:08:13,330 --> 00:08:17,020
it is easy to add positive numbers ah how
do you add positive numbers lets give a simple
78
00:08:17,020 --> 00:08:21,040
example lets assume ah number sys a number
of the form three zero zero one one and you
79
00:08:21,040 --> 00:08:30,920
want to add this three plus two well you can
do simple binary addition as you do decimal
80
00:08:30,920 --> 00:08:39,029
addition see add one and zero you get one
you get one and one so one plus one is two
81
00:08:39,029 --> 00:08:47,920
so two and binary is one zero so you write
zero here you have one as the carry see again
82
00:08:47,920 --> 00:08:55,910
write one over here so this is zero one zero
one which is five this is absolutely fine
83
00:08:55,910 --> 00:09:00,170
its easy to add positive numbers unfortunately
its hard to add negative numbers in this particular
84
00:09:00,170 --> 00:09:08,750
ah representation and that is the sa ah that
is the sad part ah of doing this ah that adding
85
00:09:08,750 --> 00:09:18,800
negative numbers so negative numbers cannot
really be added ah the way that we added ah
86
00:09:18,800 --> 00:09:24,640
positive numbers and that will create some
problems for us ah which is not something
87
00:09:24,640 --> 00:09:33,529
that we wanted so if we want to see ah so
lets consider an example so lets see we want
88
00:09:33,529 --> 00:09:45,050
to add three plus minus two so which is three
minus to the answer should be one so three
89
00:09:45,050 --> 00:09:52,300
is zero zero one one minus two is well lets
consider plus two so this is plus two so invert
90
00:09:52,300 --> 00:10:02,040
every bit of it one one zero one then lets
add them so one plus one is zero and the carry
91
00:10:02,040 --> 00:10:12,009
is one ah one plus one is two so the carry
is one one plus one is again zero one one
92
00:10:12,009 --> 00:10:15,759
plus one again zero one again zero
so clearly this answer is not correct this
93
00:10:15,759 --> 00:10:25,509
answer is wrong and this produces an output
carry a one which is again you know not correct
94
00:10:25,509 --> 00:10:32,680
so the answer should have been equal to one
over here which is clearly not the case so
95
00:10:32,680 --> 00:10:39,360
we do not have a number system where its easy
to va perform arithmetic operations on both
96
00:10:39,360 --> 00:10:50,880
positive and negative numbers so when nevertheless
the point to notice the idea of a compliment
97
00:10:50,880 --> 00:10:57,699
that we can take the compliment of every bit
and try to represent that as a number ah so
98
00:10:57,699 --> 00:11:07,589
so there can be some merits to it but ah well
so we have seen two idea the idea a sign bit
99
00:11:07,589 --> 00:11:14,459
on a compliment individually these ideas are
not that strong so before we move forward
100
00:11:14,459 --> 00:11:24,959
let me explain this formula that i have skipped
so here what are we trying to do we are considering
101
00:11:24,959 --> 00:11:30,639
a number u which can either be positive or
negative we are trying to map it this is the
102
00:11:30,639 --> 00:11:41,499
set s we are trying to map it to a sequence
of binary numbers ah a sequence of binary
103
00:11:41,499 --> 00:11:50,069
digits where n is its unsigned or positive
form so ah for positive numbers we do nothing
104
00:11:50,069 --> 00:11:56,370
it is u itself u is greater than or equal
to zero and for negative numbers we what we
105
00:11:56,370 --> 00:12:00,160
do is we take the value of u and we compliment
every single bit of it whether tilde sign
106
00:12:00,160 --> 00:12:07,249
is also the sign for a bitwise compliment
alternatively what we can do is also you consider
107
00:12:07,249 --> 00:12:16,269
minus three how did we get here we took zero
zero one one and ah we essentially subtracted
108
00:12:16,269 --> 00:12:22,800
this number from this number
so if you subtract anything from one you actually
109
00:12:22,800 --> 00:12:30,189
get its compliment we can clearly see why
one minus one is zero one minus one is zero
110
00:12:30,189 --> 00:12:35,390
one minus zero is one one minus zero is one
which is low and behold the representation
111
00:12:35,390 --> 00:12:38,160
for minus three these methods are algebraically
equivalent so ah so lets a given a boolean
112
00:12:38,160 --> 00:12:45,699
variable x if i consider x compliment that
is also the same as one minus x why is this
113
00:12:45,699 --> 00:12:54,519
the case assume that x is zero x compliment
is one and one minus x is also one assume
114
00:12:54,519 --> 00:13:01,750
x is one x compliment is zero and one minus
one is also zero
115
00:13:01,750 --> 00:13:11,760
so what we are doing over here is that so
two to the power n minus one ah in a four
116
00:13:11,760 --> 00:13:19,300
bit number system would be fifteen which is
represented as all ones so take a compliment
117
00:13:19,300 --> 00:13:24,709
of a number we can also subtract its absolute
value from two to the power n minus one so
118
00:13:24,709 --> 00:13:32,559
we will get the compliment of the number so
there are two ways of thinking about how to
119
00:13:32,559 --> 00:13:40,059
take a ones compliment ah one is we take a
compliment every single bit or we subtract
120
00:13:40,059 --> 00:13:48,810
the number from two to the power n minus one
in this case n is four because we have four
121
00:13:48,810 --> 00:13:54,259
bits so two to the power n minus one is fifteen
so we can subtract it from fifteen in a sense
122
00:13:54,259 --> 00:13:56,870
its equivalent to complimenting every single
bit
123
00:13:56,870 --> 00:14:02,829
so already discuss this problem has this approach
has the set of problems the biggest problem
124
00:14:02,829 --> 00:14:05,500
is there are two representations was zero
and adding a positive two and negative number
125
00:14:05,500 --> 00:14:08,120
or a negative two a negative number is hard
and this is not something that we would want
126
00:14:08,120 --> 00:14:16,070
to do so then ah lets consider one more approach
called a bias based approach ah which is used
127
00:14:16,070 --> 00:14:20,959
in a different number system will have a chance
to talk about it
128
00:14:20,959 --> 00:14:24,259
ah so you consider four bit number system
with the bias equal to seven so what are we
129
00:14:24,259 --> 00:14:28,999
trying to do we are saying that it take any
number is representation is a number plus
130
00:14:28,999 --> 00:14:32,380
the bias fine so lets see minus three its
representation would be minus three plus seven
131
00:14:32,380 --> 00:14:36,339
so minus three plus seven is equal to four
and its binary representation is zero one
132
00:14:36,339 --> 00:14:40,689
zero zero similarly if you take plus three
will be three plus seven which is equal to
133
00:14:40,689 --> 00:14:43,810
ten and this is exactly what we have eight
plus zero plus two plus zero which is ten
134
00:14:43,810 --> 00:14:47,330
in decimal
if we want to add two numbers its easy so
135
00:14:47,330 --> 00:14:50,829
in this case addition of number is easy ah
all that we need to do is the representation
136
00:14:50,829 --> 00:14:55,869
of u plus v f of u plus v is f u plus f v
minus bias so we can clearly see why thats
137
00:14:55,869 --> 00:15:00,629
the case lets say i want to do three plus
minus three so this would be equivalent to
138
00:15:00,629 --> 00:15:06,490
ah adding four sorry ah so so basically we
are adding zero one zero zero plus one zero
139
00:15:06,490 --> 00:15:14,449
one zero so this is zero one one one so this
in decimal is fourteen when we need to subtract
140
00:15:14,449 --> 00:15:20,490
the bias which is equivalent to seven so if
you subtract this in decimal we get seven
141
00:15:20,490 --> 00:15:25,769
and what is seven seven well is the representation
for zero because in our system f of zero the
142
00:15:25,769 --> 00:15:33,889
representation of zero zero plus the bias
which is zero plus seven equal to seven so
143
00:15:33,889 --> 00:15:40,149
this so what do we have we have f of three
plus minus three is equal to f of zero which
144
00:15:40,149 --> 00:15:50,350
is exactly the answer that we wanted so the
advantage of this system is there is only
145
00:15:50,350 --> 00:15:51,959
one representation for zero which is the bias
and zero for zero two representations are
146
00:15:51,959 --> 00:15:53,999
not there the other is at doing addition and
subtraction is fairly easy there is absolutely
147
00:15:53,999 --> 00:16:01,389
no problem ah in doing in ah doing an addition
subtraction can be slightly difficult ah not
148
00:16:01,389 --> 00:16:07,389
very difficult those so if you consider subtraction
so lets try to subtract f of three minus three
149
00:16:07,389 --> 00:16:11,929
so this is essentially equal to
so in this case instead of subtracting the
150
00:16:11,929 --> 00:16:20,779
bias you add the bias so this is equal to
seven which is the same as so subtraction
151
00:16:20,779 --> 00:16:24,379
is also easy but multiplication is difficult
so now we have seen three kinds of systems
152
00:16:24,379 --> 00:16:27,519
one was the ones compliment system ah one
is ah this particular approach which is the
153
00:16:27,519 --> 00:16:28,519
bias based approach and other was the sign
magnitude system so lets now discuss one approach
154
00:16:28,519 --> 00:16:31,361
which is used and it is used for a very good
reason ah there it has very good ah so wa
155
00:16:31,361 --> 00:16:38,860
wa what are the reasons once again the reasons
are we need one representation for zero that
156
00:16:38,860 --> 00:16:45,190
is point number one ah we should have some
nice mathematical properties in the sense
157
00:16:45,190 --> 00:16:53,059
that ah we should be able to nicely add and
subtract and multiply the number may be not
158
00:16:53,059 --> 00:16:58,009
divide so oul all are repre previous representations
were simple but they fell short
159
00:16:58,009 --> 00:17:02,180
so lets do one thing lets consider the set
of all four bit numbers and ah try to represent
160
00:17:02,180 --> 00:17:08,360
them as a circle so this is called the number
circle so lets just ah consider zero one two
161
00:17:08,360 --> 00:17:15,050
three four five six till fifteen and from
zero till fifteen so each one of them i have
162
00:17:15,050 --> 00:17:21,650
its binary unsigned representation and so
one thing that you see is set at fifteen and
163
00:17:21,650 --> 00:17:26,680
zero i have placed a line like this ah as
a discontinuity and as i travel clockwise
164
00:17:26,680 --> 00:17:33,810
ah the numbers are getting incremented so
clockwise a increment and if i travel anti
165
00:17:33,810 --> 00:17:39,160
clockwise which is the other direction this
way i am decrementing the numbers did you
166
00:17:39,160 --> 00:17:44,480
or did you seen the numbers by one so what
i can do if i can do something really interesting
167
00:17:44,480 --> 00:17:52,040
i can take the same numbers circle and use
the concept as a signed bit so i can treat
168
00:17:52,040 --> 00:17:57,840
all of these numbers from zero till seven
as positive numbers and after seven ah i can
169
00:17:57,840 --> 00:18:06,600
treat them as negative numbers but i will
treat them in a negative number in a special
170
00:18:06,600 --> 00:18:09,110
way so after zero one one one ah the next
number is one zero zero so let me call this
171
00:18:09,110 --> 00:18:12,290
minus eight and then minus seven minus six
ah minus one and so on so the red one over
172
00:18:12,290 --> 00:18:16,500
here are my set of negative numbers so so
a note that in this case the pointer there
173
00:18:16,500 --> 00:18:20,550
is no discontinuity of this point say minus
one va here and zero here but there is a point
174
00:18:20,550 --> 00:18:22,120
of discontinuity over here that we call the
breakpoint
175
00:18:22,120 --> 00:18:26,080
so lets now take a look at some of the salient
features of making a number circle like this
176
00:18:26,080 --> 00:18:30,870
as i moved clockwise by essentially increment
the number other than are the breakpoint so
177
00:18:30,870 --> 00:18:36,130
as you see as i moved clockwise i am incrementing
the number so this is feature number one that
178
00:18:36,130 --> 00:18:39,274
this clockwise increment is there in this
particular number circle second the notation
179
00:18:39,274 --> 00:18:40,840
of the sign bit is there in the sense that
if you take a look at all the positive numbers
180
00:18:40,840 --> 00:18:42,230
their m s b of the most significant bit is
zero and if you take a look at all the negative
181
00:18:42,230 --> 00:18:43,750
numbers their m s b of the most significant
bit is equal to one so in that sense the notation
182
00:18:43,750 --> 00:18:45,450
of the sign bit is there and it has been preserved
so this will come useful
183
00:18:45,450 --> 00:18:46,450
so le lets now try to use the number circle
so lets assume that you want to add m to the
184
00:18:46,450 --> 00:18:47,450
number n so the first thing that we do is
we locate n on the number circle if m is positive
185
00:18:47,450 --> 00:18:48,450
we move m steps clockwise because every single
step that we move we increment the number
186
00:18:48,450 --> 00:18:49,450
by one similarly if ah if m is negative we
move m steps anticlockwise or ah so moving
187
00:18:49,450 --> 00:18:50,450
m steps anticlockwise will essentially decrement
the number and this is equivalent so so here
188
00:18:50,450 --> 00:18:51,450
is the very very important point so moving
so in this case lets let me consider in this
189
00:18:51,450 --> 00:18:52,450
point four i want to subtract two so i can
move two steps anticlockwise one step second
190
00:18:52,450 --> 00:18:53,450
step so moving two steps anticlockwise is
exactly the same as moving fourteen steps
191
00:18:53,450 --> 00:18:54,450
clockwise right so this is a very very important
point that all of us need to remember this
192
00:18:54,450 --> 00:18:55,450
the cracks of this approach that moving two
steps anticlockwise is exactly the same as
193
00:18:55,450 --> 00:18:56,450
moving fourteen steps clockwise which is exactly
what we are trying to say that in an n bit
194
00:18:56,450 --> 00:18:57,450
number system moving m steps anticlockwise
is the same as moving two to the power n minus
195
00:18:57,450 --> 00:18:58,950
m steps clockwise clearly if we cross the
breakpoint we can have an overflow which means
196
00:18:58,950 --> 00:19:00,640
a number is too large or too small to be represented
but we will discuss such special cases later
197
00:19:00,640 --> 00:19:01,640
so keeping these things in mind let us ah
define the twos complement notation so the
198
00:19:01,640 --> 00:19:02,640
twos complement notation is something like
this so we will represent positive numbers
199
00:19:02,640 --> 00:19:03,640
as we were doing as long as a number is between
zero and to the power n minus one minus one
200
00:19:03,640 --> 00:19:04,640
sin a four bit number system two to the power
n minus one is two to the power four minus
201
00:19:04,640 --> 00:19:05,640
one and minus one so this comes out to be
two to the power three eight minus one which
202
00:19:05,640 --> 00:19:06,640
is seven so as long as the number in between
zero and seven all inclusive we will represent
203
00:19:06,640 --> 00:19:07,640
it as u which is exactly what we are doing
in the number circle that a number between
204
00:19:07,640 --> 00:19:08,640
zero and seven less represented as the unsigned
binary representation of the number itself
205
00:19:08,640 --> 00:19:09,640
however if a number the moment it becomes
negative then what we will do and the number
206
00:19:09,640 --> 00:19:12,462
is between minus two to the power n minus
one which is like in a four bit number system
207
00:19:12,462 --> 00:19:13,462
minus eight and zero we will represent this
as two to the power n minus the absolute value
208
00:19:13,462 --> 00:19:15,430
of u so this is very interesting why this
is done
209
00:19:15,430 --> 00:19:16,710
so lets start from point zero lets assume
that i want to represent minus five so minus
210
00:19:16,710 --> 00:19:18,510
five is same as zero minus five so i should
walk five steps anticlockwise so one two three
211
00:19:18,510 --> 00:19:20,960
four and five i reach over here so the other
is at the crux of the idea is walking five
212
00:19:20,960 --> 00:19:22,420
steps anticlockwise is also walking leven
steps eleven steps clockwise so are the representation
213
00:19:22,420 --> 00:19:24,000
of minus five should be the same as walking
eleven steps clockwise which is plus eleven
214
00:19:24,000 --> 00:19:26,080
and you will see this is exactly the case
that we have eight plus two plus one which
215
00:19:26,080 --> 00:19:29,110
is plus eleven so this is exactly what is
being shown in this formula over here that
216
00:19:29,110 --> 00:19:36,351
in the number that in the number circle ah
representing a number of the form u will u
217
00:19:36,351 --> 00:19:38,940
is negative is the same as two to the power
n minus the absolute value of u so this is
218
00:19:38,940 --> 00:19:41,110
like walking u steps absolute value of u steps
anticlockwise from zero or moving these many
219
00:19:41,110 --> 00:19:43,430
steps clockwise
so f u in this case is index of a point on
220
00:19:43,430 --> 00:19:44,430
the number circle and this will vary from
zero to two to the power n minus one so ah
221
00:19:44,430 --> 00:19:46,820
simple examples for plus four what we do for
plus four what we do is we represent it its
222
00:19:46,820 --> 00:19:50,360
within the range of the number system zero
and seven so we represent this is zero one
223
00:19:50,360 --> 00:19:52,310
zero zero for minus four the way we represent
this is very simple we just to sixteen minus
224
00:19:52,310 --> 00:19:53,310
four which is twelve and this is exactly the
representation of twelve in the binary system
225
00:19:53,310 --> 00:19:54,310
which is eight plus four is twelve similarly
for plus five ah what we do is that ah we
226
00:19:54,310 --> 00:19:55,310
represent this as a regular unsigned binary
integer which is zero one zero one and for
227
00:19:55,310 --> 00:19:56,310
minus three well is very simple we just ah
to take a look at the formula over here and
228
00:19:56,310 --> 00:19:57,310
its representation will be sixteen minus absolute
value of three which is plus thirteen and
229
00:19:57,310 --> 00:19:58,310
this is plus thirteen is eight plus four plus
one which is twelve plus one equals thirteen
230
00:19:58,310 --> 00:19:59,310
now lets considered properties of the twos
complement notation ah so typically in any
231
00:19:59,310 --> 00:20:00,310
n ah notation ah the first property that we
look at is the range of the number system
232
00:20:00,310 --> 00:20:01,310
so what we yet seen is that for a four bit
ah number system the range was between minus
233
00:20:01,310 --> 00:20:02,310
eight to plus seven this can be extended to
ah an n bit number system where the ranges
234
00:20:02,310 --> 00:20:03,310
between minus two to the power n minus one
so you can substitute the value of four over
235
00:20:03,310 --> 00:20:04,310
here and ill find its minus eight two ah plus
seven
236
00:20:04,310 --> 00:20:05,310
ah so this is the first property ah so one
thing that we can ah infer from here is that
237
00:20:05,310 --> 00:20:06,310
we have one more negative integer than the
number of positive integers ah that is because
238
00:20:06,310 --> 00:20:07,310
we have to accommodate for zero also there
is a single unique representation for zero
239
00:20:07,310 --> 00:20:08,310
which is all zeros which is a very good thing
this is something that we wanted the most
240
00:20:08,310 --> 00:20:09,310
significant ah so third property is are the
most significant bit of f u which is the representation
241
00:20:09,310 --> 00:20:10,310
of a sign number in this notation is equal
to the sign bit of u so why is this the case
242
00:20:10,310 --> 00:20:11,310
ah lets go back to the number circle and the
answer is there so if we considered all the
243
00:20:11,310 --> 00:20:12,310
positive numbers ah their ah most significant
bit is zero which is the sign bit of the number
244
00:20:12,310 --> 00:20:13,310
if you consider all the negative numbers ah
written in red their most significant bit
245
00:20:13,310 --> 00:20:14,310
or sign bit is plus one ah which is what we
get to see for all the number over here so
246
00:20:14,310 --> 00:20:15,310
its very easy to find if a number in the twos
complement notation is positive or negative
247
00:20:15,310 --> 00:20:16,310
we just take a look at its m s b the most
significant bit
248
00:20:16,310 --> 00:20:17,310
ah so alternatively this is more of a generic
proof that is f u is less than two to the
249
00:20:17,310 --> 00:20:18,310
power plus and minus one the m s b is zero
ah you can answer its positive and for a negative
250
00:20:18,310 --> 00:20:19,310
number it needs be greater than equal to two
to the power n minus one it needs to cross
251
00:20:19,310 --> 00:20:20,310
the breakpoint in the number circle this is
this is a breakpoint and ah this find the
252
00:20:20,310 --> 00:20:21,310
m s b becomes equal to one thus the number
is negative
253
00:20:21,310 --> 00:20:22,310
ah now lets look at some more properties say
every number in the range in the range of
254
00:20:22,310 --> 00:20:23,310
the number system has a unique mapping because
it has a unique point in the number circle
255
00:20:23,310 --> 00:20:24,310
so ah why is this called the twos complement
system will take a look at it in the next
256
00:20:24,310 --> 00:20:25,310
two properties but first let us define ah
something simple we define ah this point where
257
00:20:25,310 --> 00:20:26,310
this operator called equivalence with three
arrows i am sorry three horizontal lines this
258
00:20:26,310 --> 00:20:27,310
means that they refer to the same point on
the number circle or alternatively a is equal
259
00:20:27,310 --> 00:20:28,310
to b mod two to the power n and so we can
see if why so lets consider a four bit number
260
00:20:28,310 --> 00:20:29,310
system and so lets consider point three if
we add sixteen to three ah then we just need
261
00:20:29,310 --> 00:20:30,310
to walk sixteen steps in the clockwise direction
will again come back to three so essentially
262
00:20:30,310 --> 00:20:31,310
three is equivalent to nineteen in the system
the reason being that three is equal to nineteen
263
00:20:31,310 --> 00:20:32,310
mod sixteen for sixteen is two to the power
four
264
00:20:32,310 --> 00:20:33,310
so the advantage of ah having this particular
notation is that we can say that a lot of
265
00:20:33,310 --> 00:20:34,310
numbers on the number line are equivalent
because there is only one representation for
266
00:20:34,310 --> 00:20:35,310
them on the number circle and out of them
only one is in the range or the number system
267
00:20:35,310 --> 00:20:36,310
and the others are not so now lets come to
the first serious property of the twos complement
268
00:20:36,310 --> 00:20:37,310
notation
so lets take a number u so we want to find
269
00:20:37,310 --> 00:20:38,310
the notation of the number minus u so this
is equivalent to where this is the same operator
270
00:20:38,310 --> 00:20:39,310
that we have defined two to the power n minus
f of u so this is ah so let me first give
271
00:20:39,310 --> 00:20:40,310
an example and then we will look at the proof
of this so consider the representation of
272
00:20:40,310 --> 00:20:41,310
minus four this is equal to sixteen minus
the representation of plus four the rep representation
273
00:20:41,310 --> 00:20:42,310
of plus four is just four so this is essentially
equal to twelve binary representation which
274
00:20:42,310 --> 00:20:43,310
is one one zero zero
so it is very easy to find the representation
275
00:20:43,310 --> 00:20:44,310
of the negative of any ah number simply by
subtracting it from two to the power n and
276
00:20:44,310 --> 00:20:45,310
this is also why this is called a twos complement
number system because we are subtracting it
277
00:20:45,310 --> 00:20:46,310
from two to the power n ah thats the reason
now ah if you want to take a look at ah a
278
00:20:46,310 --> 00:20:47,310
proof of this this can easily be proven again
with the number circle method so this is how
279
00:20:47,310 --> 00:20:48,310
will define a number circle with a breakpoint
over here so what we want to do is that if
280
00:20:48,310 --> 00:20:49,310
you want to find f of minus u this is same
as moving f u steps counter clockwise is this
281
00:20:49,310 --> 00:20:50,310
so basically moving f u steps in a counter
clockwise direction is the same as moving
282
00:20:50,310 --> 00:20:51,310
two to the power minus f u steps in a clockwise
direction starting from zero so what we are
283
00:20:51,310 --> 00:20:52,310
seeing is that assume ah so sl lets consider
if u is positive then we will have f of minus
284
00:20:52,310 --> 00:20:53,310
u is two to the power man ah n minus u so
what we need to do is that the location for
285
00:20:53,310 --> 00:20:54,310
u and the number circle lets at this point
and the location of minus u is let see this
286
00:20:54,310 --> 00:20:55,310
point so f of minus u we can get by ah essentially
starting at zero and walking two to the power
287
00:20:55,310 --> 00:20:56,310
n minus u steps in the clockwise direction
which will bring us exactly over here because
288
00:20:56,310 --> 00:20:57,310
if you walk two to the power n steps will
again come back at the origin and at this
289
00:20:57,310 --> 00:20:58,310
point will exactly reach two to the power
n minus u ah which is exactly the same as
290
00:20:58,310 --> 00:20:59,310
walking minus u steps in the counter clockwise
direction
291
00:20:59,310 --> 00:21:00,310
so what we can see that if u is positive this
relationship holds similarly if u is negative
292
00:21:00,310 --> 00:21:01,310
its also easy to prove the same relationship
this i leave for the reader but the important
293
00:21:01,310 --> 00:21:02,310
point to note ah in this number circle based
logic is that walking u steps in a certain
294
00:21:02,310 --> 00:21:03,310
direction is same as walking two to the power
n minus u steps in a opposite direction this
295
00:21:03,310 --> 00:21:04,310
is a very important point to understand for
all of us ah that in in a number circle so
296
00:21:04,310 --> 00:21:05,310
when you are walking in one direction you
are incrementing walking in the other direction
297
00:21:05,310 --> 00:21:06,310
you are decrementing so when we lets see want
to compute the notation of minus u f of minus
298
00:21:06,310 --> 00:21:07,310
u so ah minus u is basically means that we
start at the origin and we move u steps in
299
00:21:07,310 --> 00:21:08,310
the counter clockwise direction which is exactly
the same as we move f u steps in the clockwise
300
00:21:08,310 --> 00:21:09,310
ah i am sorry ah which essentially means that
we move two to the power min ah n minus f
301
00:21:09,310 --> 00:21:10,310
u steps in the clockwise direction to reach
the same point
302
00:21:10,310 --> 00:21:11,310
so now lets take a look at some of the basic
properties of a twos complement number system
303
00:21:11,310 --> 00:21:12,310
and see how you know whats the real advantage
of this so actually the the twos complement
304
00:21:12,310 --> 00:21:13,310
system has some wonderful properties mathematical
properties and thats very interesting so lets
305
00:21:13,310 --> 00:21:14,310
do one thing lets start at a point u so what
we want to prove is a basic rule for addition
306
00:21:14,310 --> 00:21:15,310
that f of u plus v where we adding two numbers
their representation on the number circle
307
00:21:15,310 --> 00:21:16,310
the point is the same as f u plus f v so this
basically means that we can add the representations
308
00:21:16,310 --> 00:21:17,310
of u and v we just do a simple binary addition
and that will be the representation of u plus
309
00:21:17,310 --> 00:21:18,310
v
so ah ah what we do we start at point u its
310
00:21:18,310 --> 00:21:19,310
index is f u so lets first assume that v is
positive so then we move v points clockwise
311
00:21:19,310 --> 00:21:20,310
and will arrive at f u plus v ah so the its
index will be equal to f u plus v mod two
312
00:21:20,310 --> 00:21:21,310
to the power n and since v is equal to f v
we will have this relationship which is exactly
313
00:21:21,310 --> 00:21:22,310
equal to this relationship is just equal to
represented by ah sorry substituted by the
314
00:21:22,310 --> 00:21:23,310
equivalent sign so we will just have for positive
v f of u plus v is exactly the same as f u
315
00:21:23,310 --> 00:21:24,310
plus f of v
so let me give an example to ah explain this
316
00:21:24,310 --> 00:21:25,310
point lets assume you want to add two plus
three in binary so the representation of this
317
00:21:25,310 --> 00:21:26,310
would be zero zero one zero plus zero zero
one one right so basically we can say that
318
00:21:26,310 --> 00:21:27,310
f of five which is two plus three is equal
to f two plus f three which is equal to zero
319
00:21:27,310 --> 00:21:28,310
zero one zero in binary plus zero zero one
one which is zero one zero one
320
00:21:28,310 --> 00:21:29,310
now lets consider v to be negative so we consider
v to be negative what do we need to do we
321
00:21:29,310 --> 00:21:30,310
need to start at the point u on the number
circle with representation f u and we need
322
00:21:30,310 --> 00:21:31,310
to move modulus of v points anticlockwise
so this is the same as moving two to the power
323
00:21:31,310 --> 00:21:32,310
n minus mod v points clockwise so we will
then arrive at f u plus v since f v is equal
324
00:21:32,310 --> 00:21:33,310
to two to the power n minus mod v the index
f u plus v this number is will be equal to
325
00:21:33,310 --> 00:21:34,310
f u plus two to the power n minus mod v mod
to the power n of course which is equivalent
326
00:21:34,310 --> 00:21:35,310
to f u plus f v mod two to the power n
so what we see that this relationship holds
327
00:21:35,310 --> 00:21:36,310
for both positive v as well as negative v
so lets consider again an example lets assume
328
00:21:36,310 --> 00:21:37,310
that we want to compute two plus minus four
in binary so the representation of two plus
329
00:21:37,310 --> 00:21:38,310
minus four what we are seeing is f of two
plus f of minus four so f of two if we consider
330
00:21:38,310 --> 00:21:39,310
an binary zero zero one zero if i consider
f of minus four that is essential essentially
331
00:21:39,310 --> 00:21:40,310
equal to f of twelve sixteen minus four which
is zero zero one zero plus one one zero zero
332
00:21:40,310 --> 00:21:41,310
so lets proceed an add no problem so what
we get is we get one one one zero which is
333
00:21:41,310 --> 00:21:42,310
actually the representation of so this is
plus fourteen because this is four ah i am
334
00:21:42,310 --> 00:21:43,310
sorry two plus four plus eight which is plus
fourteen which is actually f of minus two
335
00:21:43,310 --> 00:21:44,310
which is exactly the answer that we needed
to get two plus minus four is minus two so
336
00:21:44,310 --> 00:21:45,310
what we can see is that both for positive
v as well as negative v if we need to add
337
00:21:45,310 --> 00:21:46,310
two numbers for the represented in the twos
complement binary notation we just simply
338
00:21:46,310 --> 00:21:47,310
need to add them and the final result will
be the representation of what the final result
339
00:21:47,310 --> 00:21:48,310
should be write the result of this addition
over here will be the representation of what
340
00:21:48,310 --> 00:21:49,310
the final result which is u plus v should
be
341
00:21:49,310 --> 00:21:50,310
now lets consider subtraction lets assume
we want to subtract u minus v so this from
342
00:21:50,310 --> 00:21:51,310
the previous theorem is f u plus f of minus
v which is f u plus two to the power n minus
343
00:21:51,310 --> 00:21:52,310
f of v
so subtraction in a sense is the same as addition
344
00:21:52,310 --> 00:21:53,310
you just compute the twos complement ah f
v say lets consider an example lets see that
345
00:21:53,310 --> 00:21:54,310
i want to subtract in a four bit number system
three minus five so this i can write ah f
346
00:21:54,310 --> 00:21:55,310
of three plus two to the power n which is
sixteen minus f of five so we will be writing
347
00:21:55,310 --> 00:21:56,310
in both binary and decimal notations ah the
notation needs to be sort of inferred from
348
00:21:56,310 --> 00:21:57,310
the context so in this case f of three is
equal to three ah so i am not writing it in
349
00:21:57,310 --> 00:21:58,310
binary to just keep the representation ah
simple and f of five is equal to five
350
00:21:58,310 --> 00:21:59,310
so this is equal to fourteen which is equal
to f of minus two this is exactly what we
351
00:21:59,310 --> 00:22:00,310
wanted to ah prove so o one thing that we
see is that adding or multiplying ah i am
352
00:22:00,310 --> 00:22:01,310
sorry adding or subtracting ah twos complement
numbers is actually very easy for addition
353
00:22:01,310 --> 00:22:02,310
we just go ahead and add and if we want to
subtract we essentially added with its twos
354
00:22:02,310 --> 00:22:03,310
complement so here is a trick question food
for thought does a similar relationship hold
355
00:22:03,310 --> 00:22:04,310
for multiplication as well right ah this is
something that needs to be proven and this
356
00:22:04,310 --> 00:22:05,310
actually does hold so this actually does hold
and this is a ah very nice property of the
357
00:22:05,310 --> 00:22:06,310
twos complement notation doesnt hold for division
but at least for multiplication this property
358
00:22:06,310 --> 00:22:07,310
definitely does hold and this is very very
useful property so lets may be consider an
359
00:22:07,310 --> 00:22:08,310
example
so lets consider you want to multiply two
360
00:22:08,310 --> 00:22:09,310
times minus three we claim that this is equivalent
to f of two times f of minus three say f of
361
00:22:09,310 --> 00:22:10,310
two is equal to two because a representation
of two is two on a number circle and similarly
362
00:22:10,310 --> 00:22:11,310
f of minus three is actually thirteen because
its sixteen minus three so this is equivalent
363
00:22:11,310 --> 00:22:12,310
to twenty six which is equivalent to ten because
we take always mod sixteen so mod sixteen
364
00:22:12,310 --> 00:22:13,310
means consider the four lower bits and so
this is equivalent to ten or i can write twenty
365
00:22:13,310 --> 00:22:14,310
six mod sixteen which is essentially equal
to ten which is equal to f of minus six why
366
00:22:14,310 --> 00:22:15,310
minus six because f of minus six is equal
to sixteen minus six is equal to ten so this
367
00:22:15,310 --> 00:22:16,310
is exactly what we had set out to prove that
f of two times minus three is f of minus six
368
00:22:16,310 --> 00:22:17,310
and ah a low and behold we have a proof over
here
369
00:22:17,310 --> 00:22:18,310
so now the question is that we want to prove
this result for any arbitrary u and v so let
370
00:22:18,310 --> 00:22:19,310
me prove some of the sub cases and some cases
i will leave as an exercise to the reader
371
00:22:19,310 --> 00:22:20,310
con consider u and v both are positive u both
are positive then we have f of u times v is
372
00:22:20,310 --> 00:22:21,310
just u times v of course when there are no
overflows we will discuss that later multiplied
373
00:22:21,310 --> 00:22:22,310
by u times v which is really true consider
the fact that both u and v are negative so
374
00:22:22,310 --> 00:22:23,310
then ah lets look at ah say if u and v both
are negative the product is positive so the
375
00:22:23,310 --> 00:22:24,310
r h s still u multiplied with v where as the
l h s is two to the power n ah so maybe i
376
00:22:24,310 --> 00:22:25,310
can just write it mod u times mod v just to
make things ah straight forward
377
00:22:25,310 --> 00:22:26,310
so since we take ah all of these numbers mod
two to the power n so why do we do that because
378
00:22:26,310 --> 00:22:27,310
the ranger the number system is n bits more
than that we cant represent so since we take
379
00:22:27,310 --> 00:22:28,310
everything mod two to the power n we can cancel
out all of these terms so since this term
380
00:22:28,310 --> 00:22:29,310
gets cancelled and this term gets cancelled
what we are left with is mod u multiplied
381
00:22:29,310 --> 00:22:30,310
with mod v and thus l h s is equal to r h
s the only other case that we need to prove
382
00:22:30,310 --> 00:22:31,310
is when u is positive and v is negative and
when u is negative and v is positive is an
383
00:22:31,310 --> 00:22:32,310
exactly symmetric case so we just need to
prove one so you need to so the reader needs
384
00:22:32,310 --> 00:22:33,310
to prove the case when u is positive and v
is negative the reader needs to prove this
385
00:22:33,310 --> 00:22:34,310
result and this i leave as an exercise
so how do i compute the twos complement very
386
00:22:34,310 --> 00:22:35,310
quickly well ah lets take a look at what needs
to be done ah so one thing that can be done
387
00:22:35,310 --> 00:22:36,310
is that lets say i want compute the twos complement
of ah four in ah minus four so in this case
388
00:22:36,310 --> 00:22:37,310
what do i do ah what i do is that i do sixteen
minus four which is twelve so i am essentially
389
00:22:37,310 --> 00:22:38,310
subtracting four from two to the power n to
get twelve so i am doing a competition of
390
00:22:38,310 --> 00:22:39,310
the form two to the power n minus u which
can be broken down into two to the power minus
391
00:22:39,310 --> 00:22:40,310
n minus one minus u plus one if ah readers
would kindly recall this is the ones complement
392
00:22:40,310 --> 00:22:41,310
so two to the power n minus one lets see what
kind of a number it is further you consider
393
00:22:41,310 --> 00:22:42,310
two to the power four minus one which is fifteen
its one one one one
394
00:22:42,310 --> 00:22:43,310
so two to the power n minus one is essentially
equal to one one one one n times say this
395
00:22:43,310 --> 00:22:44,310
minus any binary number at every point was
just assuming have a one over here you will
396
00:22:44,310 --> 00:22:45,310
get zero here a zero over here you will get
a one here see you just get the complement
397
00:22:45,310 --> 00:22:46,310
of the number so this is called the ones complement
so what we can do is that we can take the
398
00:22:46,310 --> 00:22:47,310
ones complement and add one to it which is
exactly what we get to see in this particular
399
00:22:47,310 --> 00:22:48,310
representation ah this is a nice way in binary
to actually get the ones complement of a number
400
00:22:48,310 --> 00:22:49,310
and to add one to it ah so for example if
you want to compute minus four we first find
401
00:22:49,310 --> 00:22:50,310
the complement and then add one to it and
this is the representation of minus four
402
00:22:50,310 --> 00:22:51,310
now lets take a look at one more trick ah
in the rim of twos complement numbers its
403
00:22:51,310 --> 00:22:52,310
called sign extension so suppose we conver
convert a n bit number to a m bit twos complement
404
00:22:52,310 --> 00:22:53,310
number right so the idea here is that assume
ah that this is a four bit number and you
405
00:22:53,310 --> 00:22:54,310
want to convert it to an eight bit number
so what do you do so assume that the number
406
00:22:54,310 --> 00:22:55,310
is positive so in almost all proofs we ah
sort or divide it into two sub cases in one
407
00:22:55,310 --> 00:22:56,310
sub case the number is positive and in the
other sub case the number is negative
408
00:22:56,310 --> 00:22:57,310
so lets consider that i have a number of the
form in a plus four represented in binary
409
00:22:57,310 --> 00:22:58,310
zero one zero zero and i want to convert it
into an eight bit positive number all that
410
00:22:58,310 --> 00:22:59,310
i need to do is that in the four m s b positions
most significant positions at four zeros so
411
00:22:59,310 --> 00:23:00,310
this is a valid representation in a eight
bit number system
412
00:23:00,310 --> 00:23:01,310
now lets assume that the number is negative
so lets consider minus four so minus fours
413
00:23:01,310 --> 00:23:02,310
representation is one one zero zero in the
twos complement system so we need to calculate
414
00:23:02,310 --> 00:23:03,310
what would be the representation of minus
four in a eight bit number system right so
415
00:23:03,310 --> 00:23:04,310
minus four how do we get this number this
is actually the decimal form is twelve and
416
00:23:04,310 --> 00:23:05,310
see sixteen minus four in eight bits we need
to compute two to the power eight minus four
417
00:23:05,310 --> 00:23:06,310
so two to the power eight is two hundred fifty
six minus four
418
00:23:06,310 --> 00:23:07,310
so lets do a little bit of algebra so lets
assume so this is the representation of number
419
00:23:07,310 --> 00:23:08,310
in the m bit number system this is the representation
of the number in the n bit number systems
420
00:23:08,310 --> 00:23:09,310
so lets just subtract if you subtract we get
two to the power m minus two to the power
421
00:23:09,310 --> 00:23:10,310
n so ah if we would actually subtracted what
we would find is the result is two to the
422
00:23:10,310 --> 00:23:11,310
power n plus two to the power n plus one till
two to the power m minus one so maybe just
423
00:23:11,310 --> 00:23:12,310
giving an example
lets see you want to subtract two to the power
424
00:23:12,310 --> 00:23:13,310
four minus two to the power two which is sixteen
minus four which is twelve right so the claim
425
00:23:13,310 --> 00:23:14,310
here is that this is equal to two to the power
two plus two to the power three which is four
426
00:23:14,310 --> 00:23:15,310
plus eight so this is a very easy identity
to prove and ah so i leave this to the reader
427
00:23:15,310 --> 00:23:16,310
but the interesting part is that if i take
this expression and i convert it into binary
428
00:23:16,310 --> 00:23:17,310
what i would get is that i would get n zeros
and the remaining m minus n ones all right
429
00:23:17,310 --> 00:23:18,310
so this is exactly what i would get that i
would get n zeros and m minus n ones now assume
430
00:23:18,310 --> 00:23:19,310
that the representation in a four bit number
system of a number of the form minus u right
431
00:23:19,310 --> 00:23:20,310
for u is positive is two to the power n minus
u and lets see an eight bit number system
432
00:23:20,310 --> 00:23:21,310
we have this equal to two to the power m minus
u where n is four and m is equal to eight
433
00:23:21,310 --> 00:23:22,310
so what we have we have this relationship
over here that f of eight minus u is actually
434
00:23:22,310 --> 00:23:23,310
equal to two to the power n minus u which
is again an n bit number right which is an
435
00:23:23,310 --> 00:23:24,310
n bit number plus this expression over here
for the first n bits are all zeros and the
436
00:23:24,310 --> 00:23:25,310
remaining ones are all ones so i would consider
a relationship of a a num i am sorry a number
437
00:23:25,310 --> 00:23:26,310
of this type which is m minus n ones and the
rest n are zeros right so if i add this number
438
00:23:26,310 --> 00:23:27,310
plus this number what i will get is that the
first m minus n positions you know will still
439
00:23:27,310 --> 00:23:28,310
be sorry the first m minus n positions will
still be ones and then the remaining positions
440
00:23:28,310 --> 00:23:29,310
over here will be occupied by whatever is
a representation of two to the power n minus
441
00:23:29,310 --> 00:23:30,310
u right for the remaining n positions since
this number is negative the m s b of this
442
00:23:30,310 --> 00:23:31,310
part will also be one and the remaining will
be ones all right
443
00:23:31,310 --> 00:23:32,310
so the important point to note is that whatever
is a representation in the four bit number
444
00:23:32,310 --> 00:23:33,310
systems so lets ag again consider f of minus
four f of minus four in a four bit number
445
00:23:33,310 --> 00:23:34,310
sys system was one one zero zero say f of
minus four in an eight bit number system ss
446
00:23:34,310 --> 00:23:35,310
will first p one one zero zero and the rest
all the positions will be equal to one so
447
00:23:35,310 --> 00:23:36,310
the readers can manually verify the this is
exactly what comes why another calculation
448
00:23:36,310 --> 00:23:37,310
which is two fifty six minus four so this
is also the representation of ah two hundred
449
00:23:37,310 --> 00:23:38,310
and fifty two all right and ah so what we
say is that they sign bit over here we can
450
00:23:38,310 --> 00:23:39,310
think of it as getting replicated ah across
the rest of the new positions this is exactly
451
00:23:39,310 --> 00:23:40,310
what was happening for positive numbers that
the sign bit for the four bit number was getting
452
00:23:40,310 --> 00:23:41,310
replicated across the new positions that ah
new positions to the left and here also the
453
00:23:41,310 --> 00:23:42,310
sign bit is being replicated towards the new
positions on the left so this trick is called
454
00:23:42,310 --> 00:23:43,310
sign extension that to convert a negative
number from ah n bit number system to an m
455
00:23:43,310 --> 00:23:44,310
bit number system you add m minus n ones in
the most significant m s b positions so what
456
00:23:44,310 --> 00:23:45,310
we can do just summarizing and closing the
discussion is that in both cases extend the
457
00:23:45,310 --> 00:23:46,310
sign bit by m minus n positions for example
if i want to convert from a four bit to an
458
00:23:46,310 --> 00:23:47,310
eight bit system ah number system and my number
is zero zero one zero all that i do is i add
459
00:23:47,310 --> 00:23:48,310
four zeros to the left of it if i have one
number of the form one zero one one i just
460
00:23:48,310 --> 00:23:49,310
had four ones to the left of it so essentially
take a look at the sign bit whatever it is
461
00:23:49,310 --> 00:23:50,310
i just extend the sign bit replicated across
ah the positions to the left
462
00:23:50,310 --> 00:23:51,310
now lets consider one more point so which
is called an overflow theorem so the overflow
463
00:23:51,310 --> 00:23:52,310
theorem is something like this so lets assume
that in a four bit number system we want to
464
00:23:52,310 --> 00:23:53,310
add five plus five so five plus five the answer
is ten but ten cannot be represented in four
465
00:23:53,310 --> 00:23:54,310
bits the reason being that the largest number
that can be represented is actually plus seven
466
00:23:54,310 --> 00:23:55,310
so in this case we say that we have an overflow
which means that the number cannot be represented
467
00:23:55,310 --> 00:23:56,310
in the particular number system similarly
if i add minus five and minus five it will
468
00:23:56,310 --> 00:23:57,310
be minus ten but the range of the four bit
number system is only till minus eight so
469
00:23:57,310 --> 00:23:58,310
ah we cant do the addition as a result will
also have an overflow in this case
470
00:23:58,310 --> 00:23:59,310
so the overflow theorem is something like
this that if i am adding u plus v and if u
471
00:23:59,310 --> 00:24:00,310
v is less than zero which means one of them
one of the numbers u or v is positive and
472
00:24:00,310 --> 00:24:01,310
the other one is negative we will never have
an overflow so to prove this let us go back
473
00:24:01,310 --> 00:24:02,310
to the number circle so there will be an overflow
only when we cross the breakpoint otherwise
474
00:24:02,310 --> 00:24:03,310
you are within the range of the number circle
so u v is equal to zero one of the numbers
475
00:24:03,310 --> 00:24:04,310
is ah you know if u v is equal to zero means
one of the numbers is zero so one of the numbers
476
00:24:04,310 --> 00:24:05,310
is zero then not be any overflow if u v is
greater than zero an overflow is possible
477
00:24:05,310 --> 00:24:06,310
and we just saw an example of this where we
are adding five and five or adding minus five
478
00:24:06,310 --> 00:24:07,310
and minus five now u v is less than zero lets
see what will happen
479
00:24:07,310 --> 00:24:08,310
lets say that you want to add one and minus
four to we start at one and we count four
480
00:24:08,310 --> 00:24:09,310
positions in the anticlockwise direction so
we can clearly see that we are not crossing
481
00:24:09,310 --> 00:24:10,310
the breakpoint so there is no overflow right
this is the breakpoint but if we had ah u
482
00:24:10,310 --> 00:24:11,310
and v both as positive and ah in this simple
two bit number system that we have ah we can
483
00:24:11,310 --> 00:24:12,310
clearly see that we are crossing the breakpoint
and there will be an overflow so i am adding
484
00:24:12,310 --> 00:24:13,310
one and three so to add three i need to move
three steps clockwise and i will cross the
485
00:24:13,310 --> 00:24:14,310
breakpoint and so one and three is not minus
four its actually plus four is the wrong answer
486
00:24:14,310 --> 00:24:15,310
so i am having an overflow
so what are the conditions for an overflow
487
00:24:15,310 --> 00:24:16,310
if u v is less than equal to zero will never
have an overflow if u v is greater than zero
488
00:24:16,310 --> 00:24:17,310
means say the same sign ah we can have an
overflow but when will we have will have an
489
00:24:17,310 --> 00:24:18,310
overflow when the sign of the result is greater
than is different from the sign of both u
490
00:24:18,310 --> 00:24:19,310
and v right in this case u and v both are
positive and ah we add them ah so ah if the
491
00:24:19,310 --> 00:24:20,310
result is negative we know there is an overflow
similarly if we lets say we are adding minus
492
00:24:20,310 --> 00:24:21,310
three and minus two so i can start it minus
three to add minus two i need to travel two
493
00:24:21,310 --> 00:24:22,310
steps in the anticlockwise direction so i
come here and then i come here right and so
494
00:24:22,310 --> 00:24:23,310
the answer that i get is plus three which
can never be the answer because minus three
495
00:24:23,310 --> 00:24:24,310
and minus two are both negative numbers so
the answer cannot be positive
496
00:24:24,310 --> 00:24:25,310
so then also i will find that i am having
an overflow so in the book there is a very
497
00:24:25,310 --> 00:24:26,310
detailed proof of this result and so in the
slides you know this is a last slides we are
498
00:24:26,310 --> 00:24:27,310
not presenting a result but i will just give
you an overview of the proof but the detailed
499
00:24:27,310 --> 00:24:28,310
proof is there in the book and i would request
all readers to go to the book and ah take
500
00:24:28,310 --> 00:24:29,310
a look at the proof so the proof goes somewhat
like this
501
00:24:29,310 --> 00:24:30,310
so lets go back to this example so lets assume
that ah you know with no loss of generality
502
00:24:30,310 --> 00:24:31,310
u is positive and v is negative right u v
is less than zero so if you start at a positive
503
00:24:31,310 --> 00:24:32,310
point to have an overflow i need to sort of
cross this breakpoint right so to cross this
504
00:24:32,310 --> 00:24:33,310
breakpoint ah so let me assume a contra positive
that you can have an overflow so the best
505
00:24:33,310 --> 00:24:34,310
possible way that i can have one you know
to maximize my chances i would like to meet
506
00:24:34,310 --> 00:24:35,310
u as small as possible and the absolute value
of v as large as possible so the smallest
507
00:24:35,310 --> 00:24:36,310
value of u ah that is not negative is zero
and the lar and the largest absolute value
508
00:24:36,310 --> 00:24:37,310
of v is actually four so the v will become
minus four
509
00:24:37,310 --> 00:24:38,310
so if i add zero plus minus four i will still
ah come over here which is in the range of
510
00:24:38,310 --> 00:24:39,310
the number system and i will not cross the
breakpoint right so basically whatever i do
511
00:24:39,310 --> 00:24:40,310
i will not be able to cross the breakpoint
and thus i will not have an overflow so this
512
00:24:40,310 --> 00:24:41,310
is a very high level ah hand wavy kind of
proof but ah better proof and a very rigorous
513
00:24:41,310 --> 00:24:42,310
mathematical proof is there in the book thats
the reason i am asking you to go there and
514
00:24:42,310 --> 00:24:43,310
similarly if you know if i consider any other
examples lets i start at two i need to travel
515
00:24:43,310 --> 00:24:44,310
more than seven steps to actually cross the
breakpoint and sort of need to add minus seven
516
00:24:44,310 --> 00:24:45,310
and since minus seven is not in the range
of the number system will not have an overflow
517
00:24:45,310 --> 00:24:46,310
so this is why if one of the number is positive
and other is negative or the other is zero
518
00:24:46,310 --> 00:24:47,310
we will not have an overflow but if both the
numbers has a same sign we can always cross
519
00:24:47,310 --> 00:24:48,310
the breakpoint as we have seen now reader
can argue that is it possible for the two
520
00:24:48,310 --> 00:24:49,310
numbers to have the same sign and i will cross
the breakpoint have an overflow with the result
521
00:24:49,310 --> 00:24:50,310
will also have the same sign which means maybe
i start from this point i add a positive number
522
00:24:50,310 --> 00:24:51,310
and i walk all the way up and then i again
my result is in the positive half of the number
523
00:24:51,310 --> 00:24:52,310
circle this will never happen the reason this
will never happen is so my best cases that
524
00:24:52,310 --> 00:24:53,310
i start at lets say three and add three so
one step two and three the result is still
525
00:24:53,310 --> 00:24:54,310
negative on in the other case i can start
at minus four and add minus four in this case
526
00:24:54,310 --> 00:24:55,310
one step two step three and four right because
i am walking anticlockwise now the result
527
00:24:55,310 --> 00:24:56,310
is still non negative
so what we see is that respective or whatever
528
00:24:56,310 --> 00:24:57,310
you do if i am adding two numbers with the
same sign and the result is of a different
529
00:24:57,310 --> 00:24:58,310
sign of then opposite sign i can always infer
an overflow which is exactly what the overflow
530
00:24:58,310 --> 00:24:59,310
theorem is trying to tell you that if one
of the numbers is zero will never have an
531
00:24:59,310 --> 00:25:00,310
overflow a one is positive the other is negative
will never have an overflow only when both
532
00:25:00,310 --> 00:25:01,310
the numbers u and v have the same sign would
we actually have an overflow in a condition
533
00:25:01,310 --> 00:25:01,326
is the sign of the result should be different
from the sign of both the numbers