6:09 there is a problem in the written code while loop condition will be (n != 0) instead of (n != 1) if we are using while(n != 1) , then we have to explicitly push back 1 to end of the string after the while loop ends
Already have known these in the past, but after watching this video I was amazed as I had forgotten many things already. It was like having the knowledge for the first time lol.
Helpful tip for calculating 2's complement go from LSB(least significant bit) to MSB(most significant bit) basically from right to left do so till u get the first " 1 " and then just flip the remaining digits for 2's complement:) say 13 - 0000......1101 2's comp - 11111....0011
At last negation operation part 34:30 onwards So, i think bhaiya got a little confused by that, lemme break it down correctly. so on using the negation operation "~" this simply flips all bits and store the result. nothing much.. just simple flip all bits. Let's work out with case of positive number consider n = 5 = 00000000000000000000000000000101 now, ~n = 11111111111111111111111111111010 this is what is stored inside computer, now upon reading this number when we require it somewhere to be printed or anything. the computer looks at the 31st bit and sees it is set, thus the number is negative, thus a negative sign will be put and now to fetch its value, computer perform 2's complement. So, 00000000000000000000000000000101
At 30:50 when you are taking 2's complement, you are not flipping the signed bit, but at 37:00 , when you are taking 2's complement again in another example, you are flipping the signed bit as well.... please explain , if I am missing something or clear my confusion
after completing your amazing dp playlist, now I started this playlist , your voice sound a bit different here 😄 Thanks brother for the amazing content.
There is an error in the code 9:44 it doesn't matter if there is one or not you have to update the value of p2 for (int i = a.length() - 1; i >= 0; i--) { if (a.charAt(i) == '1') { num += p2; } p2 *= 2; }
Understood.....what you are saying....we can pushback that '1' in end or we can change the condition in starting from checking to 0 ( while (n!=0) )to avoid adding 1 in last ......hope if it is clear now 😅
hi Striver i have a question 6:25 you were explaining the time complexity of the code log base 2 n but the reverse function will take 0(n) time complexity so eventually the code will take 0(n) or log n?
I was waiting for this such a long time...Bits manipulation is super fun but was reluctant to learn cos of missing Striver-Factor Well now we have it and the community couldnt be more blessed❤.. Thank u Gurudev apnake onek onek ashirbadh r shubhechaa ❤
when doing NOT ,in 2's complement why the sign bit doesn't change? but when we storing negative number, at that time in 2's complement sign bit is changing. can you please clear this? @takeUforward
And the reason why 2’s complement is used is interesting you should check it out if we reserve the left most bit directly for the sign there will be 2 zeros one for positive and another for negative but the 2’s complement removes this issue
I have a question, if it stores a negative number as 2's complement so at 27:51, how will the computer know that the number is 13 only? because you can see a lot of 1 are there
36:54 bhaiya you said a negative number is stored with first bit as a negative sign so -6 in binary format will start with 100000......and so on with last few bits as 0000110. It's a little bit confusing.
At last negation operation part 34:30 onwards So, i think bhaiya got a little confused by that, lemme break it down correctly. so on using the negation operation "~" this simply flips all bits and store the result. nothing much.. just simple flip all bits. Let's work out with case of positive number consider n = 5 = 00000000000000000000000000000101 now, ~n = 11111111111111111111111111111010 this is what is stored inside computer, now upon reading this number when we require it somewhere to be printed or anything. the computer looks at the 31st bit and sees it is set, thus the number is negative, thus a negative sign will be put and now to fetch its value, computer perform 2's complement. So, 00000000000000000000000000000101
def binary_to_decimal(binary_string): res = 0 base = 1 for i in range(len(binary_string) - 1, -1, -1): num_added = binary_string[i] == "1" res += (base * num_added) base *= 2 return res
Can someone confirm at 35:57 you get the sign to be negative and flip all bits to get 6. And that's how you get -6. The computer stores 2's complement 11111...010.
Striver thank you very much. God bless you ❤ Please could you explain how to rotate number by k steps. K may be less than 0 or greater than 32 If it is < 0 rotate right , if positive rotate left.
I understand that negative numbers are stored in 2's complement format. Can you explain why? Why can't we just change the sign bit and leave the rest of the bits as they are to change the number from positive to negative?
In 36:13 I noticed a small mistake The ~ (tilde operator) or (flip operator) doesn't work like that It JUST FLIPS... it doesn't check and convert's to 2's compliment... Here's the explaination Lets say u have ....................................5 = (0000000000........0101) Now u flip the bits it using tilde ....... ~5= (1111111111........1010) just google what's the value of (1111111111........1010). It's literally -6. So the extra step u mentioned of [checking negative & converting to 2's compliment doesn't happens]. U may ask, then why this weird binary's value is -6 In binary the negative numbers are actually 2's compliment. They are kinda in a reverse order 2 = 000000.............0010 1 = 000000.............0001 0 = 000000.............0000 -1 = 111111.............1111 -2 = 111111.............1110 -3 = 111111.............1101 and so on... for further ref : stackoverflow.com/questions/68319054/representation-of-negative-numbers-in-binary www.quora.com/How-is-negative-numbers-represented-in-binary-code Hope it helps!
For INT_MIN you have made the binary as 1(-ve) 0 0 0 ....0 0 0 0 this is representing ZERO not the INT_MIN before calculating two's complement Correct me if i'm wrong
35:57 here , when we flipped the number the sign bit became 1 ,when we check it came out to be a negative number so we have to do it's 2's complement then but why sign bit is left unchanged please answer me . @takeyouforward
Great Explanation! I have a doubt. Why does the sign bit did not change during x~5 while performing 2's compliment. And when we are doing x~-6 he change the sign of 31 bit during 2's compliment. Someone please answer this.
Respect button for striver bhaiya-->
just striver, dont add bhaiya
need likes huh?
Same guy goes behind shraddha "didi" like a dog😂
He's striver not bhaiya
bhai arrow ke side mai report button aa rha hai ky kru ?? daba du
Respect for this man 💗.......The man who changed the myth DSA is hard
Most Awaited Playlist... Bit Manipulation!
Remember if striver is making than this will be the best bit manipulation playlist on youtube
larn inglis
@@chad._life chal beta aage nikal 😂
6:09 there is a problem in the written code
while loop condition will be (n != 0) instead of (n != 1)
if we are using while(n != 1) , then we have to explicitly push back 1 to end of the string after the while loop ends
I was about to comment the same , good observation :)
I too observed the same.
Yeah
also we can just the concept of indexes and math.pow() function
Yep I also noticed when I coded
Thank you very much striver ,
You are teaching us and working at the same time and too providing us with the best video that to free ,
I'm Grateful.
Next, we want strings
@take U forward
Yes we want string
I was thinking of learning bit manipulation and here you are 🔥
just completed lt1 now moving on to the 2nd one.
a big thanks to you bhaiya.
Thank you so much striver, you have changed my mind about coding
Thanks a lot striver for your great effort!!! In this video 13 played a hero role...
i was the guy who requested striver bhaiya to make playlist on bit manipulation. cheers guys☺
no it was me
nahi me tha mene call kiya tha striver bhai ko playlist ke liye to unhone thik hai upload krta hu bolke upload krdi bit manipulation
@@abhinav6726 hn lekin twitter par maine bola tha
ask him to make on strings
@@soumi6720 bol dunga, but wants to know more about hu
Legend is back🔥
Already have known these in the past, but after watching this video I was amazed as I had forgotten many things already. It was like having the knowledge for the first time lol.
Truly appreciate this content. I finally get to understand bit manipulation
This playlist helps us to learn bit manipulation
no shit
most awaited series Mann! you are great
No one can teach DSA like you sir❤❤.
Thank you Striver for this Amazing Playlist....😊
Helpful tip for calculating 2's complement go from LSB(least significant bit) to MSB(most significant bit) basically from right to left do so till u get the first " 1 " and then just flip the remaining digits for 2's complement:)
say 13 - 0000......1101 2's comp - 11111....0011
Finally Bit Manipulation 🎉
Thank You Bhaiya ❤
At last negation operation part 34:30 onwards
So, i think bhaiya got a little confused by that, lemme break it down correctly. so on using the negation operation "~" this simply flips all bits and store the result. nothing much.. just simple flip all bits.
Let's work out with case of positive number
consider
n = 5 = 00000000000000000000000000000101
now,
~n = 11111111111111111111111111111010
this is what is stored inside computer, now upon reading this number when we require it somewhere to be printed or anything. the computer looks at the 31st bit and sees it is set, thus the number is negative, thus a negative sign will be put and now to fetch its value, computer perform 2's complement. So,
00000000000000000000000000000101
Thanks a lot for this detailed explanation man
Thanks a lot bro. This cleared all my confusion!
thanks brother
Actually I have done all questions of bit Manipulation from ATOZ DSA sheet but still watching for one and only striver bhaiya
i am so happy .. keep doing hard work
for those who have confusion on negative numbers, revisit this 25:34
I wonder my dsa, if Striver Sir weren't in youtube.Thanku Sir.
i am appreciating your effort
also make playlist for greedy and stack & queues
At 30:50 when you are taking 2's complement, you are not flipping the signed bit, but at 37:00 , when you are taking 2's complement again in another example, you are flipping the signed bit as well.... please explain , if I am missing something or clear my confusion
He made a mistake it Just flips either way even if it is positive or negative
Thank You So Much for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
a perfect lecture for intro of bit.
East or West Striver bhaiya is best 💯
after completing your amazing dp playlist, now I started this playlist , your voice sound a bit different here 😄
Thanks brother for the amazing content.
concepts are cleared❤❤
thank you striver Bhaiya❤
Understood,thanks striver for this amazing video.
Finally learned this stuff after avoiding it for so long
Was eagerly waiting for the video
That really cleared my fear of Bits . Thank u .
There is an error in the code 9:44 it doesn't matter if there is one or not you have to update the value of p2
for (int i = a.length() - 1; i >= 0; i--) {
if (a.charAt(i) == '1') {
num += p2;
}
p2 *= 2;
}
finally!!!!!!!!!!! can't be more happy ❤🔥❤🔥❤🔥❤🔥❤🔥
Hey bro just one request from my side is please try to complete whole sheet as soon as possible the sheet is legendary thanks again for giving it free
Bhai aap bahut acche padhate hai
At 5:27 n!=1 is wrong n!=0 is correct
Waiting from 2 months for this playlist.
hey, striver in the function converting decimal to binary 4:26 we will manually need to add "1" to the res string at the end , right ?
I guess while checking the condition we can check for 0 in place of 1..... as by writing 0 all the cases will be covered
@@tanya7463 no i mean to say the last wala bit LSB is not being considered by striver. wo digram me jo middle bottom 1 hai wo
Understood.....what you are saying....we can pushback that '1' in end or we can change the condition in starting from checking to 0 ( while (n!=0) )to avoid adding 1 in last ......hope if it is clear now 😅
@@tanya7463 yup
Yaaaay... Finally Bit Manipulation... Ab lagegi job sbki
36:13 why sign bit doesn,t affect by complement
signed bit flip karenge toh positive ka NOT positive he rahega. It doesn't make sense then
hi Striver i have a question 6:25 you were explaining the time complexity of the code log base 2 n but the reverse function will take 0(n) time complexity so eventually the code will take 0(n) or log n?
Thank you striver, and now only I think strings playlist is balance
I was waiting for this such a long time...Bits manipulation is super fun but was reluctant to learn cos of missing Striver-Factor
Well now we have it and the community couldnt be more blessed❤.. Thank u Gurudev apnake onek onek ashirbadh r shubhechaa ❤
thank you so much
these lectures are so so good
Great job bhai.
Thank you so much Striver 😭😭
6:59 at the end we have used the reverse function therefore the tc should be nlogn not logn ?
wow after long time _new Playlist is coming, sir can you make a playlist on "Two pointer"....Thank you❤❤❤❤
Trick for 2s compliment in O(n)
Start from end, the moment you encounter 1, you start flipping the bits that appear after it.
when doing NOT ,in 2's complement why the sign bit doesn't change? but when we storing negative number, at that time in 2's complement sign bit is changing. can you please clear this? @takeUforward
29:41 To find the smallest negative number, why you used "1000000......0" instead we can use "1111111......1". please explain 😭
Because negative numbers are stored as 2’s complement
And the reason why 2’s complement is used is interesting you should check it out if we reserve the left most bit directly for the sign there will be 2 zeros one for positive and another for negative but the 2’s complement removes this issue
I have a question, if it stores a negative number as 2's complement
so at 27:51, how will the computer know that the number is 13 only? because you can see a lot of 1 are there
Shouldn't the TC be O(logn) + O(n) at 6:30 as we are using reverse STL ?
Can someone tell me why on 36:10 sign bit is 1 , it should be 0 , correct me if I am wrongg?
thank you so much for this course, we know that the course is probably draining you, as is visible from your face so pls take rest when you need to
Thank you for this series🙏🙏
Striver is going to destroy the dsa market by giving High level of free content 😂
Very well explained, but there is bug is a small bug in convert2Decimal function kindly keep p2 = p2 * 2 outside if condition
36:54 bhaiya you said a negative number is stored with first bit as a negative sign so -6 in binary format will start with 100000......and so on with last few bits as 0000110. It's a little bit confusing.
At last negation operation part 34:30 onwards
So, i think bhaiya got a little confused by that, lemme break it down correctly. so on using the negation operation "~" this simply flips all bits and store the result. nothing much.. just simple flip all bits.
Let's work out with case of positive number
consider
n = 5 = 00000000000000000000000000000101
now,
~n = 11111111111111111111111111111010
this is what is stored inside computer, now upon reading this number when we require it somewhere to be printed or anything. the computer looks at the 31st bit and sees it is set, thus the number is negative, thus a negative sign will be put and now to fetch its value, computer perform 2's complement. So,
00000000000000000000000000000101
@@ashurajput6916 respect for you brother
Thank you very much for your dedication
there is a mistake in 4:42 "number to binary" code -> if(n!=1) => you are leaving the last 1 after the division.
it should be -> if(n!=0)
comeback shuru
9:42 , code is written if the binary of no is present in reverse.
Isn' it ??
Bas ab String or Heaps reh gya 😊 jaldi complete kardo bhaiya inhe v
Great Content !, Can you extend this playlist by adding bitmask and bitmask DP? Thank you!
what happen to string module which was before linkedlist??
THANK YOU STRIVER...🙂
Sir plz make playlist on sliding window
100th like from me was my pleasure ❤
I really like this man
Much needed topic 😅
def binary_to_decimal(binary_string):
res = 0
base = 1
for i in range(len(binary_string) - 1, -1, -1):
num_added = binary_string[i] == "1"
res += (base * num_added)
base *= 2
return res
Wait is over 🥳🥳🥳🥳
Thank youu STRIVER💃
Bhaiya there in while loop condition 6:29. It should be n!=0 or n>0 instead of n!=1
mistake at 36:00 we only have to flip 0s to 1 and 1 to 0 , no need to check for negative conditions
flip will give answer for ~
Bhai while loop ki condition alg ayge :
while(n>0) hoga
Love you Bhai so much❤
Understood. Thank you!
Waiting for String playlist
Can someone confirm at 35:57 you get the sign to be negative and flip all bits to get 6. And that's how you get -6. The computer stores 2's complement 11111...010.
Striver thank you very much. God bless you ❤
Please could you explain how to rotate number by k steps. K may be less than 0 or greater than 32
If it is < 0 rotate right , if positive rotate left.
A2Z sheet is not updated with notes and video links for bit manipulation.
Lots Lots Lots of Love 🤟
I understand that negative numbers are stored in 2's complement format. Can you explain why? Why can't we just change the sign bit and leave the rest of the bits as they are to change the number from positive to negative?
In 36:13 I noticed a small mistake
The ~ (tilde operator) or (flip operator) doesn't work like that
It JUST FLIPS... it doesn't check and convert's to 2's compliment... Here's the explaination
Lets say u have ....................................5 = (0000000000........0101)
Now u flip the bits it using tilde ....... ~5= (1111111111........1010)
just google what's the value of (1111111111........1010). It's literally -6.
So the extra step u mentioned of [checking negative & converting to 2's compliment doesn't happens].
U may ask, then why this weird binary's value is -6
In binary the negative numbers are actually 2's compliment. They are kinda in a reverse order
2 = 000000.............0010
1 = 000000.............0001
0 = 000000.............0000
-1 = 111111.............1111
-2 = 111111.............1110
-3 = 111111.............1101
and so on...
for further ref :
stackoverflow.com/questions/68319054/representation-of-negative-numbers-in-binary
www.quora.com/How-is-negative-numbers-represented-in-binary-code
Hope it helps!
for reversing string doesnt it take tc of 0(n/2) ~0(n) ,and it is greater than logarthimic tc right.
Much needed one
Thalaivaaa❤
For INT_MIN you have made the binary as 1(-ve) 0 0 0 ....0 0 0 0 this is representing ZERO not the INT_MIN before calculating two's complement
Correct me if i'm wrong
Thanks and I promise I will finish by tommorow
did you?
@@Monika-vs6bw yup done ..
35:57 here , when we flipped the number the sign bit became 1 ,when we check it came out to be a negative number so we have to do it's 2's complement then but why sign bit is left unchanged please answer me . @takeyouforward
Strings (hard problems) ka video solutions or Articles add kardo bhaiya ❤
Great Explanation! I have a doubt.
Why does the sign bit did not change during x~5 while performing 2's compliment. And when we are doing x~-6 he change the sign of 31 bit during 2's compliment.
Someone please answer this.
He did wrong