Apna College - Bitwise Operators, Data Type Modifiers & more | DS..
Category
📚
LearningTranscript
00:00Hi everyone and welcome to the complete DSA series in which we are going to do our next
00:09lecture.
00:10In this lecture, we will cover a lot of important concepts like our bitwise operators, scope
00:15of a variable or our data type modifiers.
00:18If we want to study any other concept in DSA, then we will get it available on this channel
00:23in this playlist.
00:24We can go and learn it if we want.
00:25So let's start with our chapter, we are basically going to cover a lot of miscellaneous concepts
00:38in this chapter.
00:39The first concept is of bitwise operators.
00:43We have already covered the binary number system in the last lecture.
00:47Bitwise operators, which are our numbers, perform operations on the binary form of numbers.
00:55For example, let's first talk about our bitwise AND operator, it is called bitwise AND operator.
01:01Bitwise AND is very similar to logical AND.
01:04For example, we took a 0 bit and we took a 0 bit, so both the ANDs will be 0.
01:10If we took a 0 bit and a 1 bit, then both the ANDs will also be 0.
01:13If we take the AND of 1 and 0 bit, so this is also going to be 0.
01:17Only the AND of 1 and 1 bit is 1.
01:21So this logic is very similar to logical AND operator, which we have already covered.
01:26For example, let's take two numbers, let's suppose A is equal to 4 and B is equal to 8.
01:32And we want to calculate A and B.
01:35So what will be the answer to this?
01:38The binary form of 4 is 100, and the binary form of 8 is 1000.
01:44So what we will do is, we will try to take the AND of both of them.
01:48If there is a mismatch in the number of bits, then what we can do is,
01:51we can make both of them equal by adding these 0s in the front of the number.
01:55Now when we take the AND of both of them, how will things work?
01:58The AND of 0 and 0 is 0, the AND of 0 and 0 is also 0, the AND of 1 and 0 is also 0, and the AND of 0 and 1 is also 0.
02:04So the answer to this is, this is going to be 0 of decimal.
02:07That means if we take the AND of 4 and 8 bitwise, then the answer will be equal to 0.
02:11Let's also verify this with the help of our code.
02:14So in the code, if we create two numbers, A is equal to 4 and B is equal to 8,
02:19and if we get C out, 4 or A and B,
02:24then the answer will be equal to 0.
02:29Now just like we have bitwise AND, we also have bitwise OR.
02:33Bitwise OR is very similar to logical OR.
02:36In bitwise OR, if we take the OR of 0 and 0, then this is going to be 0.
02:40And if we take the OR of 0 and 1, then it will also be 1.
02:43And if we take the OR of 1 and 0, it will also be 1.
02:45Similarly if we take the OR of 4 and 8, then it will also be 1.
02:52And we shall get 0 and 1.
02:57So this is equal to 12 of decimal.
03:01So in the code, this is equal to 2 to the power 0, 2 to the power 1, 2 to the power 2, 2 to the power 3.
03:08power 3 so here basically we are adding 4 in 8 so the answer is going to be 12 of decimal
03:13let's verify this also like here instead of AND if we do OR then we will get answer 12
03:18of decimal now in the same way like logical AND logical OR is similar to bitwise AND and
03:24bitwise OR but we have one more operator in bits which is bitwise XOR operator XOR means
03:34exclusive OR but we will always call it XOR XOR operation symbol for XOR looks like this
03:41which is available on our keyboard XOR rule says if our bits are same then answer will
03:50be 0 and if our bits are different then answer will be 1 like if we take 0 XOR 0 then answer
03:58will be 0 or if we take 1 XOR 1 then also answer will be 0 but if we take 0 XOR 1 then
04:05answer will be 1 or if we take 1 XOR 0 then also answer will be 1 like for example if we
04:12take 4 XOR with 8 so in XOR 0 0 this will give us 0 this will also give us 0 this will
04:18give us 1 and this will also give us 1 so its answer will also be 12 of decimal let's
04:23check this also here if we XOR then also in that case we are going to get our answer
04:30as 12 if we want we can try these 3 operations on any other 2 numbers also in the same way
04:36let's suppose if we want to take XOR of 3 and 7 let's save it so XOR will be equal to
04:434 now how XOR of 3 and 7 is working for 3 our binary form is this for 7 our binary form
04:51is this now when we take XOR of both if 1 1 is same then it will be 0 if 1 1 is same
04:56then it will be 0 if 0 1 is not same then it will be 1 1 0 0 is equivalent to 4 of decimal
05:02so that's why XOR of 3 and 4 is equal to 4 so in this way for any 2 decimal numbers
05:08if any operator is given to us then we can get its final answer by converting them into
05:13their binary form apart from this we have 2 more bitwise operators one is our bitwise
05:19left shift operator we call it left shift operator and this is our bitwise right shift
05:27operator now how can we remember which is left shift and which is right shift basically
05:32if we see this operator then what is here pointed end is towards left here it is looking
05:37like our operator is being pulled towards right so that is why this is right shift and
05:42this is the left shift operator now how do right shift and left shift operator work
05:47basically if we take any number let's suppose we take n is equal to 4 if we write n left
05:54shift left shift i then our binary form will shift towards left i places what does it mean
06:04let's suppose i wrote n left shift left shift 1 so what does it mean it means whatever
06:11n is there if n is 4 then 4 is 1 0 0 means it is on 3 spaces so every bit will shift
06:18towards left by 1 place means this 1 will shift towards left this 0 will shift towards
06:23left this 0 will shift towards left so our 3 places this 0 will come here this 0 will
06:29come here and this 1 will come towards one more left here so this 1 will come here and
06:35this 1 will come towards one more left here so this 1 will come towards one more left
06:40here so this 1 will come towards one more left here so this 1 will come towards one
06:45more left here so this 1 will come towards one more left here so this 1 will come towards
06:50one more left here so this 1 will come towards one more left here so this 1 will come towards
06:55one more left here so this 1 will come towards one more left here so this 1 will come towards
07:00one more left here so this 1 will come towards one more left here so this 1 will come towards
07:07one more left here so this 1 will come towards one more left here so this 1 will come towards
07:12one more left here so this 1 will come towards one more left here so this 1 will come towards
07:17one more left here so this 1 will come towards one more left here so this 1 will come towards
07:22one more left here so this 1 will come towards one more left here so this 1 will come towards
07:27one more left here so this 1 will come towards one more left here so this 1 will come towards
07:32one more left here so this 1 will come towards one more left here so this 1 will come towards
07:37one more left here so this 1 will come towards one more left here so this 1 will come towards
07:42one more left here so this 1 will come towards one more left here so this 1 will come towards
07:47one more left here so this 1 will come towards one more left here so this 1 will come towards
07:52one more left here so this 1 will come towards one more left here so this 1 will come towards
07:57one more left here so this 1 will come towards one more left here so this 1 will come towards
08:02one more left here so this 1 will come towards one more left here so this 1 will come towards
08:07one more left here so this 1 will come towards one more left here so this 1 will come towards
08:12one more left here so this 1 will come towards one more left here so this 1 will come towards
08:17one more left here so this 1 will come towards one more left here so this 1 will come towards
08:22one more left here so this 1 will come towards one more left here so this 1 will come towards
08:27one more left here so this 1 will come towards one more left here so this 1 will come towards
08:32one more left here so this 1 will come towards one more left here so this 1 will come towards
08:37one more left here so this 1 will come towards one more left here so this 1 will come towards
08:42one more left here so this 1 will come towards one more left here so this 1 will come towards
08:47one more left here so this 1 will come towards one more left here so this 1 will come towards
08:52one more left here so this 1 will come towards one more left here so this 1 will come towards
08:57one more left here so this 1 will come towards one more left here so this 1 will come towards
09:02one more left here so this 1 will come towards one more left here so this 1 will come towards
09:07one more left here so this 1 will come towards one more left here so this 1 will come towards
09:12one more left here so this 1 will come towards one more left here so this 1 will come towards
09:17one more left here so this 1 will come towards one more left here so this 1 will come towards
09:22one more left here so this 1 will come towards one more left here so this 1 will come towards
09:27one more left here so this 1 will come towards one more left here so this 1 will come towards
09:32one more left here so this 1 will come towards one more left here so this 1 will come towards
09:37one more left here so this 1 will come towards one more left here so this 1 will come towards
09:42one more left here so this 1 will come towards one more left here so this 1 will come towards
09:47one more left here so this 1 will come towards one more left here so this 1 will come towards
09:52one more left here so this 1 will come towards one more left here so this 1 will come towards
09:57one more left here so this 1 will come towards one more left here so this 1 will come towards
10:02one more left here so this 1 will come towards one more left here so this 1 will come towards
10:07one more left here so this 1 will come towards one more left here so this 1 will come towards
10:12one more left here so this 1 will come towards one more left here so this 1 will come towards
10:17one more left here so this 1 will come towards one more left here so this 1 will come towards
10:22one more left here so this 1 will come towards one more left here so this 1 will come towards
10:27one more left here so this 1 will come towards one more left here so this 1 will come towards
10:32one more left here so this 1 will come towards one more left here so this 1 will come towards
10:37one more left here so this 1 will come towards one more left here so this 1 will come towards
10:42one more left here so this 1 will come towards one more left here so this 1 will come towards
10:47one more left here so this 1 will come towards one more left here so this 1 will come towards
10:52one more left here so this 1 will come towards one more left here so this 1 will come towards
10:57one more left here so this 1 will come towards one more left here so this 1 will come towards
11:02one more left here so this 1 will come towards one more left here so this 1 will come towards
11:07one more left here so this 1 will come towards one more left here so this 1 will come towards
11:12one more left here so this 1 will come towards one more left here so this 1 will come towards
11:17one more left here so this 1 will come towards one more left here so this 1 will come towards
11:22one more left here so this 1 will come towards one more left here so this 1 will come towards
11:27one more left here so this 1 will come towards one more left here so this 1 will come towards
11:32one more left here so this 1 will come towards one more left here so this 1 will come towards
11:37one more left here so this 1 will come towards one more left here so this 1 will come towards
11:42one more left here so this 1 will come towards one more left here so this 1 will come towards
11:47one more left here so this 1 will come towards one more left here so this 1 will come towards
11:52one more left here so this 1 will come towards one more left here so this 1 will come towards
11:57one more left here so this 1 will come towards one more left here so this 1 will come towards
12:02one more left here so this 1 will come towards one more left here so this 1 will come towards
12:07one more left here so this 1 will come towards one more left here so this 1 will come towards
12:12one more left here so this 1 will come towards one more left here so this 1 will come towards
12:17one more left here so this 1 will come towards one more left here so this 1 will come towards
12:22one more left here so this 1 will come towards one more left here so this 1 will come towards
12:27one more left here so this 1 will come towards one more left here so this 1 will come towards
12:32one more left here so this 1 will come towards one more left here so this 1 will come towards
12:37one more left here so this 1 will come towards one more left here so this 1 will come towards
12:42one more left here so this 1 will come towards one more left here so this 1 will come towards
12:47one more left here so this 1 will come towards one more left here so this 1 will come towards
12:52one more left here so this 1 will come towards one more left here so this 1 will come towards
12:57one more left here so this 1 will come towards one more left here so this 1 will come towards
13:02one more left here so this 1 will come towards one more left here so this 1 will come towards
13:07one more left here so this 1 will come towards one more left here so this 1 will come towards
13:12one more left here so this 1 will come towards one more left here so this 1 will come towards
13:17one more left here so this 1 will come towards one more left here so this 1 will come towards
13:22one more left here so this 1 will come towards one more left here so this 1 will come towards
13:27one more left here so this 1 will come towards one more left here so this 1 will come towards
13:32one more left here so this 1 will come towards one more left here so this 1 will come towards
13:37one more left here so this 1 will come towards one more left here so this 1 will come towards
13:42one more left here so this 1 will come towards one more left here so this 1 will come towards
13:47one more left here so this 1 will come towards one more left here so this 1 will come towards
13:52one more left here so this 1 will come towards one more left here so this 1 will come towards
13:57one more left here so this 1 will come towards one more left here so this 1 will come towards
14:02one more left here so this 1 will come towards one more left here so this 1 will come towards
14:07one more left here so this 1 will come towards one more left here so this 1 will come towards
14:12one more left here so this 1 will come towards one more left here so this 1 will come towards
14:17one more left here so this 1 will come towards one more left here so this 1 will come towards
14:22one more left here so this 1 will come towards one more left here so this 1 will come towards
14:27one more left here so this 1 will come towards one more left here so this 1 will come towards
14:32one more left here so this 1 will come towards one more left here so this 1 will come towards
14:37one more left here so this 1 will come towards one more left here so this 1 will come towards
14:42one more left here so this 1 will come towards one more left here so this 1 will come towards
14:47one more left here so this 1 will come towards one more left here so this 1 will come towards
14:52one more left here so this 1 will come towards one more left here so this 1 will come towards
14:57one more left here so this 1 will come towards one more left here so this 1 will come towards
15:02one more left here so this 1 will come towards one more left here so this 1 will come towards
15:07one more left here so this 1 will come towards one more left here so this 1 will come towards
15:12one more left here so this 1 will come towards one more left here so this 1 will come towards
15:17one more left here so this 1 will come towards one more left here so this 1 will come towards
15:22one more left here so this 1 will come towards one more left here so this 1 will come towards
15:27one more left here so this 1 will come towards one more left here so this 1 will come towards
15:32one more left here so this 1 will come towards one more left here so this 1 will come towards
15:37one more left here so this 1 will come towards one more left here so this 1 will come towards
15:42one more left here so this 1 will come towards one more left here so this 1 will come towards
15:47one more left here so this 1 will come towards one more left here so this 1 will come towards
15:52one more left here so this 1 will come towards one more left here so this 1 will come towards
15:57one more left here so this 1 will come towards one more left here so this 1 will come towards
16:02one more left here so this 1 will come towards one more left here so this 1 will come towards
16:07one more left here so this 1 will come towards one more left here so this 1 will come towards
16:12one more left here so this 1 will come towards one more left here so this 1 will come towards
16:17one more left here so this 1 will come towards one more left here so this 1 will come towards
16:22one more left here so this 1 will come towards one more left here so this 1 will come towards
16:27one more left here so this 1 will come towards one more left here so this 1 will come towards
16:32one more left here so this 1 will come towards one more left here so this 1 will come towards
16:37one more left here so this 1 will come towards one more left here so this 1 will come towards
16:42one more left here so this 1 will come towards one more left here so this 1 will come towards
16:47one more left here so this 1 will come towards one more left here so this 1 will come towards
16:52one more left here so this 1 will come towards one more left here so this 1 will come towards
16:57one more left here so this 1 will come towards one more left here so this 1 will come towards
17:02one more left here so this 1 will come towards one more left here so this 1 will come towards
17:07one more left here so this 1 will come towards one more left here so this 1 will come towards
17:12one more left here so this 1 will come towards one more left here so this 1 will come towards
17:17one more left here so this 1 will come towards one more left here so this 1 will come towards
17:22one more left here so this 1 will come towards one more left here so this 1 will come towards
17:27one more left here so this 1 will come towards one more left here so this 1 will come towards
17:32one more left here so this 1 will come towards one more left here so this 1 will come towards
17:37one more left here so this 1 will come towards one more left here so this 1 will come towards
17:42one more left here so this 1 will come towards one more left here so this 1 will come towards
17:47one more left here so this 1 will come towards one more left here so this 1 will come towards
17:52one more left here so this 1 will come towards one more left here so this 1 will come towards
17:57one more left here so this 1 will come towards one more left here so this 1 will come towards
18:02one more left here so this 1 will come towards one more left here so this 1 will come towards
18:07one more left here so this 1 will come towards one more left here so this 1 will come towards
18:12one more left here so this 1 will come towards one more left here so this 1 will come towards
18:17one more left here so this 1 will come towards one more left here so this 1 will come towards
18:22one more left here so this 1 will come towards one more left here so this 1 will come towards
18:27one more left here so this 1 will come towards one more left here so this 1 will come towards
18:32one more left here so this 1 will come towards one more left here so this 1 will come towards
18:37one more left here so this 1 will come towards one more left here so this 1 will come towards
18:42one more left here so this 1 will come towards one more left here so this 1 will come towards
18:47one more left here so this 1 will come towards one more left here so this 1 will come towards
18:52one more left here so this 1 will come towards one more left here so this 1 will come towards
18:57one more left here so this 1 will come towards one more left here so this 1 will come towards
19:02one more left here so this 1 will come towards one more left here so this 1 will come towards
19:07one more left here so this 1 will come towards one more left here so this 1 will come towards
19:12one more left here so this 1 will come towards one more left here so this 1 will come towards
19:17one more left here so this 1 will come towards one more left here so this 1 will come towards
19:22one more left here so this 1 will come towards one more left here so this 1 will come towards
19:27one more left here so this 1 will come towards one more left here so this 1 will come towards
19:32one more left here so this 1 will come towards one more left here so this 1 will come towards
19:37one more left here so this 1 will come towards one more left here so this 1 will come towards
19:42one more left here so this 1 will come towards one more left here so this 1 will come towards
19:47one more left here so this 1 will come towards one more left here so this 1 will come towards
19:52one more left here so this 1 will come towards one more left here so this 1 will come towards
19:57one more left here so this 1 will come towards one more left here so this 1 will come towards
20:02one more left here so this 1 will come towards one more left here so this 1 will come towards
20:07one more left here so this 1 will come towards one more left here so this 1 will come towards
20:12one more left here so this 1 will come towards one more left here so this 1 will come towards
20:17one more left here so this 1 will come towards one more left here so this 1 will come towards
20:22one more left here so this 1 will come towards one more left here so this 1 will come towards
20:27one more left here so this 1 will come towards one more left here so this 1 will come towards
20:32one more left here so this 1 will come towards one more left here so this 1 will come towards
20:37one more left here so this 1 will come towards one more left here so this 1 will come towards
20:42one more left here so this 1 will come towards one more left here so this 1 will come towards
20:47one more left here so this 1 will come towards one more left here so this 1 will come towards
20:52one more left here so this 1 will come towards one more left here so this 1 will come towards
20:57one more left here so this 1 will come towards one more left here so this 1 will come towards
21:02one more left here so this 1 will come towards one more left here so this 1 will come towards
21:07one more left here so this 1 will come towards one more left here so this 1 will come towards
21:12one more left here so this 1 will come towards one more left here so this 1 will come towards
21:17one more left here so this 1 will come towards one more left here so this 1 will come towards
21:22one more left here so this 1 will come towards one more left here so this 1 will come towards
21:27one more left here so this 1 will come towards one more left here so this 1 will come towards
21:32one more left here so this 1 will come towards one more left here so this 1 will come towards
21:37one more left here so this 1 will come towards one more left here so this 1 will come towards
21:42one more left here so this 1 will come towards one more left here so this 1 will come towards
21:47one more left here so this 1 will come towards one more left here so this 1 will come towards
21:52one more left here so this 1 will come towards one more left here so this 1 will come towards
21:57one more left here so this 1 will come towards one more left here so this 1 will come towards
22:02one more left here so this 1 will come towards one more left here so this 1 will come towards
22:07one more left here so this 1 will come towards one more left here so this 1 will come towards
22:12one more left here so this 1 will come towards one more left here so this 1 will come towards
22:17one more left here so this 1 will come towards one more left here so this 1 will come towards
22:22one more left here so this 1 will come towards one more left here so this 1 will come towards
22:27one more left here so this 1 will come towards one more left here so this 1 will come towards
22:32one more left here so this 1 will come towards one more left here so this 1 will come towards
22:37one more left here so this 1 will come towards one more left here so this 1 will come towards
22:42one more left here so this 1 will come towards one more left here so this 1 will come towards
22:47one more left here so this 1 will come towards one more left here so this 1 will come towards
22:52one more left here so this 1 will come towards one more left here so this 1 will come towards
22:57one more left here so this 1 will come towards one more left here so this 1 will come towards
23:02one more left here so this 1 will come towards one more left here so this 1 will come towards
23:07one more left here so this 1 will come towards one more left here so this 1 will come towards
23:12one more left here so this 1 will come towards one more left here so this 1 will come towards
23:17one more left here so this 1 will come towards one more left here so this 1 will come towards
23:22one more left here so this 1 will come towards one more left here so this 1 will come towards
23:27one more left here so this 1 will come towards one more left here so this 1 will come towards
23:32one more left here so this 1 will come towards one more left here so this 1 will come towards
23:37one more left here so this 1 will come towards one more left here so this 1 will come towards
23:42one more left here so this 1 will come towards one more left here so this 1 will come towards
23:47one more left here so this 1 will come towards one more left here so this 1 will come towards
23:52one more left here so this 1 will come towards one more left here so this 1 will come towards
23:57one more left here so this 1 will come towards one more left here so this 1 will come towards
24:02one more left here so this 1 will come towards one more left here so this 1 will come towards
24:07one more left here so this 1 will come towards one more left here so this 1 will come towards
24:12one more left here so this 1 will come towards one more left here so this 1 will come towards
24:17one more left here so this 1 will come towards one more left here so this 1 will come towards
24:22one more left here so this 1 will come towards one more left here so this 1 will come towards
24:27one more left here so this 1 will come towards one more left here so this 1 will come towards
24:32one more left here.
24:40we have made an integer variable integer x now this integer x how much data does it store
24:46how much big integer does it store for example we know that integer has 4 bytes of memory
24:544 bytes means we already know that it has 32 bits 32 bits means in this way we have different
25:00different different different 32 0 or 1 0 or 1 combination of 0 or 1 now we know that
25:09our leftmost bit is our msb so all the positive number combinations will have leftmost bit
25:16set in it 0 will come in it all negative numbers will have msb set in it 1 will come in it
25:22and we will have to see the combinations after that so how many places are left after that
25:27one if it becomes one place then we have 31 bits left if there is a choice of 31 of 31
25:340 will come in it or 1 will come in it so total number of 0 1 combination will be equal to 2 to the power of 31
25:41this is the thing which we have studied in math in permutation combination
25:46if we have to fill 32 places with 0's and 1's then how many possible ways are there
25:51this empty space also has two choices means 0 or 1 it also has two choices it also has two choices
25:56it also has two choices all these choices are multiplied and total how many choices will be multiplied
26:0131 places are empty so total 2 to the power of 31 choices will be multiplied
26:05so if we talk about negative number then negative number can be stored up to minus 2 to the power of 31
26:10positive numbers positive 2 to the power of 31 can be stored up to minus 1 because we start these positive numbers from 0
26:17if we start from 1 then it would be 2 to the power of 31 but because in 2 to the power of 31
26:21one number is also 0 in which all the bits are 0 so this is our range which can be stored in integer
26:28if there is any difficulty in understanding this range then there is nothing to worry
26:31once you have to rewind the same explanation
26:34so if we summarize then basic summary is that if integer has given us 32 bytes
26:4032 bytes means that in this integer numbers can be stored from minus 2 to the power of 31 to plus 2 to the power of 31 minus 1
26:50but if I have to store 2 to the power of 32 then this number will be a very big number
26:55but if I have to store this number then if I try to store this number in integer then this number will not be stored exactly like this
27:02what integer will do internally it will convert it into some range of this kind
27:06and most probably a negative number will come out which will be of wrong value
27:10means integer will not be able to store the correct value because it does not have capacity
27:13there is a bucket which has a capacity of 4 liters so only 4 liters of water can come in it
27:17we cannot store 5 liters of water in it but we can increase the bucket
27:22so we can change the data type we can increase or decrease its capacity
27:26so for that we use data type modifiers among which the first modifier is long
27:31long means we can use long with long int we can use long with long double
27:37long ensures that whichever data type we use it with then what will long give us
27:42long will give us a capacity of greater than equal to 4 bytes
27:46means minimum will give 4 bytes
27:48now the capacity of data types that how many bytes each data type can store
27:52this is variable, it is not that it is fixed in all the systems
27:55depending upon our machine the capacity of our data types are different
27:59so if a student is working on an old windows system
28:04then it is possible that their integer in their system should not show 32 bits of 4 bytes
28:09their system should show 2 bytes of integer
28:11which is completely normal because our space is system dependent
28:15but long will surely ensure that whichever data type we use
28:18its capacity should be greater than equal to 4 bytes
28:21and long is generally used with integer double
28:24I have shown you as an example
28:26for example if we take an integer variable or in fact directly cout
28:32size of int
28:34we will have size of int which is going to be equal to 4
28:39but if we store long int with size of int
28:44so this time the capacity of number is greater than equal to 8 bytes
28:498 bytes means that the long int that we have made
28:53we will have 64 bits in it
28:5664 bits means that its range will be from minus 2 to the power 63
29:00to positive 2 to the power 63 minus 1
29:03so now we will be able to store a big integer number in it
29:08so in this way our long increases the size
29:11just like long increases the size, short size decreases
29:15now you must be wondering why we want to decrease the size
29:19why we want to decrease the capacity
29:21for example I want to store only the age
29:24I want to make an integer age variable
29:26now I know that age is such a thing
29:28in which I don't want to store any number
29:31maximum if I am storing the age of humans
29:34I have said 150 as well
29:36maximum age of humans has gone to 122 on record
29:39so even if I am storing up to 150
29:42still 4 bytes memory is too much
29:44so what short will do
29:46if I make int short int
29:48so it will give me space of 2 bytes
29:51means it will decrease the capacity of 4 bytes
29:56if I want to store any value
29:58whose range I know is going to be very small
30:00it is going to be a very small number
30:02like here if I try to print short int
30:07in that case we will get value equal to 2 bytes
30:10now just like we have long and short
30:12similarly we have one more modifier
30:14which is called long long
30:16long long is generally used with integers
30:19and we write it as long long int
30:22so with this also the capacity of our integer increases
30:26depending upon the system the capacity can be variable
30:28like for example if we write here
30:31long long int
30:33so in max system it is going to be equal to 8 bytes
30:36but in windows system the capacity can be different
30:39now instead of long long int
30:41if we write only long long
30:43that is also more than enough
30:45implicitly long long means long long int
30:47so it has 8 bytes of memory
30:49which we can occupy
30:51apart from this two more important
30:53we have data type modifiers
30:55one of which is signed
30:57one is unsigned
30:59generally our integer
31:01which is double or float
31:03by default it is signed
31:05we are taking integer example in majority cases
31:07because majority data type modifiers
31:09are generally used with integers
31:11so if we talk about integer
31:13by default our int is signed
31:15signed int means
31:17integer data type
31:19can store positive numbers
31:21and can store negative numbers
31:23already we have seen the range of integer
31:26so it has negative numbers
31:28and it also has positive numbers
31:31so it means it is signed data type
31:34but if we want we can
31:36make our data type unsigned
31:38now in which case we will make it unsigned
31:40for example we are using c++
31:42to build a system in which
31:44we have many customers
31:46and we want to store customer id in integer
31:48we want to store our customer id
31:50in integer
31:52so we already know that
31:54customer id will always be a positive value
31:56our customer id is never minus something
31:58customer id will always be a positive value
32:00or if we are making a banking system
32:02bank account number will always be a positive number
32:04you have never seen a negative number
32:06in real life
32:08so we know that we will never store
32:10any negative value in this variable
32:12so we can make this variable
32:14unsigned int instead of int
32:16so whenever we write
32:18unsigned integer instead of integer
32:20so unsigned integer
32:22means
32:24in this integer variable
32:26whatever is there
32:28let's call it customer id
32:30so in this customer id
32:32all the values will always be positive
32:34so now the place
32:36in our bits
32:38we had 32 bits
32:40so if we take the total bits
32:42we had 32 bits for integer
32:44so in these 32 bits
32:46now because there will be no negative number stored
32:48so this msb
32:50now we don't need to keep it as sign bit
32:52because now we know
32:54that sign of all the numbers will always be positive
32:56so this msb
32:58now we can include it to store data
33:00so now the data
33:02we can store will be
33:04from 0 to 2 to the power 32-1
33:06and 2 to the power 31
33:08is of double size
33:102 to the power 32
33:12so now in all the bits
33:14we can store double size data
33:16means customer id
33:18we can store double range
33:20so we use unsigned when we know
33:22that we have to store only positive values
33:24secondly unsigned does not increase
33:26or decrease
33:28but the data which can be stored inside
33:30that changes
33:32means now negative data will not be stored
33:34so the range of the data which can be stored will increase
33:36and we can store our customer id
33:38to more range
33:40so if we want we can verify it
33:42so if we write
33:44unsigned int x is equal to minus 10
33:46so here there will be no error
33:48this code will run without error
33:50so here we can see
33:52that x has stored minus 10
33:54but as we try to see out
33:56the value of x
33:58we will see the change
34:00and the difference is this
34:02we will not have minus 10 print
34:04we will have this value print
34:06and the reason behind this is
34:08when we assigned
34:10the value of minus 10 to unsigned int x
34:12so minus 10 will be
34:14converted into 2's complement form
34:16and in the place of 32 bits
34:18in that
34:20minus 10's 2's complement
34:22will be stored
34:24now in this binary form
34:26we know that when 2's complement of minus numbers
34:28will be there
34:30then something will be stored
34:32now this number
34:34which starts with 1
34:36if it was a normal integer
34:38then this 1 will be taken as MSB
34:40means it will be taken as sign bit
34:42but now there is no sign bit
34:44now everything is magnitude
34:46so this whole number
34:48when it is being printed
34:50so what is the compiler thinking
34:52it can't be a negative number
34:54so this is a number
34:56which starts with 1 bit
34:58so this number is this
35:00and to compute this number
35:02the reverse computation
35:04which we learned of negative numbers
35:06now it is not reverse computation
35:08now it is simply being converted into decimal
35:10means now it's 2's complement
35:12is not being taken out
35:14it's binary to decimal conversion is happening
35:16so here even though we have stored minus 10
35:18but compiler is considering it as a positive number
35:20and it is interpreting it as
35:22this big positive number
35:24that is the difference
35:26between signed and unsigned
35:28so I hope that here we understood
35:30the concept of data type modifiers
35:32this concept seems a bit mathematical to students
35:34but there is no need to worry
35:36if we pause here and think about
35:38some things a little bit mathematically
35:40then things are very easy
35:42this is very simple math which we did in school
35:44so in our chapter
35:46today we will be covering only this
35:48today basically we have covered
35:50bitwise operators
35:52in bitwise operators AND, OR and XOR
35:54along with that
35:56we have covered left shift and right shift operators
35:58along with that
36:00we have covered operator precedence
36:02that how which operator has more priority
36:04and which has less priority
36:06along with that we have covered the important concept
36:08of scope and along with that
36:10we have talked about data type modifiers
36:12that how
36:14we can modify our existing data types
36:16whether it is
36:18range of integer or
36:20concept of signed and unsigned
36:22we have covered all these things
36:24along with that I am going to give you some homework
36:26problems, first of all the problem is
36:28to figure out how to find if a number
36:30is power of 2 without any loop
36:32to make it easier, first of all
36:34you have to solve this question using loop
36:36any number given like n
36:38for example n is equal to 32
36:40for that you have to return true
36:42if the number is power of 2
36:44then you have to print false
36:46depending upon 32
36:48it will be true but if it is 34
36:50we will get false
36:52first of all you have to solve this question using loop
36:54after that you have to try to
36:56solve this question through bits
36:58in this I will tell you
37:00we are using left shift and right shift operators
37:02so how we can solve this question
37:04through bits, which we have studied in bitwise operators
37:06now this question
37:08most probably majority students
37:10will not be able to solve it
37:12so the solution of this question
37:14you can google it or take external help
37:16but you can try to figure this thing
37:18out on your own
37:20second question we can do
37:22that is to write a function to reverse an integer
37:24we can do this by ourselves
37:26most of the students who know
37:28the concept of sum of the digits
37:30basically if I am given an integer
37:32number is equal to 1 to 5
37:34so we have to print
37:36its reverse number
37:38which is 5 to 1
37:40and we don't have to just print
37:42it is not that you print 5
37:44then 2
37:46then 1
37:48this is level 1 of the problem
37:50so first of all you have to print
37:52but the original question is
37:54that you have to make a new number
37:56in which all these digits
37:58are stored in the same order
38:00so in reverse order
38:02we want to store them in one number
38:04and we want to return this number
38:06so these two problems are going to be
38:08homework problems for you
38:10I hope that from today's lecture we have learned
38:12many new things which we will implement
38:14from the next classes
38:16so if you have successfully completed the chapter
38:18you can comment below
38:20you can give yourself a pat on the back
38:22we can also update our progress on twitter
38:24and as you do homework problems
38:26you can also update your progress
38:28so that's all for today
38:30see you in the next lecture
38:32till then keep learning and keep exploring