No video

Python Tutorials - Bitwise Operators 2 (Complement, Left Shift, Right Shift)

  Рет қаралды 93,141

Amulya's Academy

6 жыл бұрын

In this Python Programming video tutorial you will learn about bitwise operators in detail.
Bitwise operators works on the bits.
There are 6 operators and in this tutorial we will discuss bitwise complement bitwise left shift and bitwise right shift operators in detail with example.
For more free tutorials on computer programming
AmulsAcademy
AmulsAcademy

Пікірлер: 149
@azharashraf3143
@azharashraf3143 4 жыл бұрын
General formula for getting result of right and left shifts are:- By using common sense, if we shift the value in the left direction our value increases, and shifting bits in the right direction value decreases. For Left shift(>>):-xy=x//(2**y)[Floor division] Example:-100>>2=100//(2*2) =>100//4 =>25 So the 100>>2=25
@sidindian1982
@sidindian1982 Жыл бұрын
Excellent Shortcut .. Sir thnx
@ianwilliam9690
@ianwilliam9690 Жыл бұрын
king shit - thank you, no idea why there are no videos on youtube that show the actual formula
@Kishor_D7
@Kishor_D7 11 ай бұрын
Thank you sir I bless you with short and happy life as if your happy life seems to be short
@vattemteja
@vattemteja 4 жыл бұрын
Why we need to add only zero's in the left shift whether it is +ve ot -ve value? why we are not adding 1's in the empty slots?
@Codeytek
@Codeytek 2 жыл бұрын
You are mind blowing! Well explained.
@TejaswiniBJBJ
@TejaswiniBJBJ 2 жыл бұрын
Can we use bin function on -ve numbers ? For example bin(-20)
@demian_762
@demian_762 2 жыл бұрын
thank you, this subjet is very complicated and you got me yo understand!
@naylamp_gaming
@naylamp_gaming 3 жыл бұрын
Thank you!! You are extremely good teacher.
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you :)
@ashwinraju7388
@ashwinraju7388 6 жыл бұрын
Thanks a lot mam,it really helped me as a beginner to python programming.enjoyed all the videos,your step by step explanations are awesome mam.
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Thank you:)
@blogsbarrel4734
@blogsbarrel4734 3 жыл бұрын
@@AmulsAcademy Show me how to do 160
@commenterdek3241
@commenterdek3241 3 жыл бұрын
@@blogsbarrel4734 0b1010000000
@abhishek.a2773
@abhishek.a2773 Жыл бұрын
Awesome amulya mam was very intresting and satisfying I loved it Thank you 🙂
@ashleyycrazy7948
@ashleyycrazy7948 Жыл бұрын
Thank u it was helpful for my exam
@MajedSalmaoun
@MajedSalmaoun Жыл бұрын
thank you really much that was really helpful ^^
@Yogi83830
@Yogi83830 Жыл бұрын
Well I'm confused in bitwise complement operator you show in the video that ~of 20 in binary 11101011 but I tried multiple times maybe im doing wrong or don't know please explain i check the binary form of -21 is -0b10101
@sujashpratihar3586
@sujashpratihar3586 4 жыл бұрын
Mam in the bitwise right shift, if there is negative number then, the no of shifted digits jitne honge front me utne hi 1 honge kya??🤔🤔
@bhukyabhanu8148
@bhukyabhanu8148 2 жыл бұрын
Gud explanation...And gud voice..and I can understand easily..
@rey4874
@rey4874 3 жыл бұрын
thanks a lot this was very easy to understand
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Glad to hear that! :)
@ammarkhan2927
@ammarkhan2927 2 жыл бұрын
That was very nice explanation
@iush7344
@iush7344 Жыл бұрын
Nice i got the topic i appreciate
@lokeshkannan6958
@lokeshkannan6958 Жыл бұрын
Super explaination
@vasudevvijay75
@vasudevvijay75 4 жыл бұрын
What if , I'm doing compliment for 21, I Will get -22, then the binary format is 00010110 for +be 22, 1's compliment= 11101001, and next I want to add 1, then how Will I get ~21 .
@poulamighosh9204
@poulamighosh9204 Жыл бұрын
Thank you🙏
@firststep3160
@firststep3160 4 жыл бұрын
Thanks a lot mam your explanation is too helpful 👍🙏🙏😘😘😍
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Thank you :)
@orangeinfotainment620
@orangeinfotainment620 4 ай бұрын
Thank You!
@eraedu4909
@eraedu4909 2 жыл бұрын
Thank you so much....
@japhethachimba174
@japhethachimba174 2 жыл бұрын
Hello mam. Can't understand the left and right shift why is the two values discarded
@arunpraveenrajs4763
@arunpraveenrajs4763 3 жыл бұрын
Awesome explanation akka... thanks a lot🙏🙏
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Welcome 😊
@jobseeker5093
@jobseeker5093 2 жыл бұрын
Seriously iam a noob with non it background but i understand very clearly, thank u girl
@tsmdesk6735
@tsmdesk6735 4 жыл бұрын
Thank you mam
@siddhesh1034
@siddhesh1034 5 жыл бұрын
Logic behind negative number right shift is not correct. I am trying to do in python 2.7.15 IDLE. (-68)>>3 giving me output as -9. How this could be -9?? If we add 111 in empty location at left side.
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
binary representation of -68 is 1011 1100 >> 3 so , 1111 0111 this is the binary representation of -9 that's why we are getting -9 in the output :)
@neatvfx
@neatvfx 3 жыл бұрын
good content and crystal clear
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@geethikaisurusampath
@geethikaisurusampath 2 жыл бұрын
Thank you
@Vyshu5
@Vyshu5 4 жыл бұрын
Thanks ma'm. It is very clear. And will you please tell me why should we use it in programming?
@ahmedchouihi
@ahmedchouihi 4 жыл бұрын
Thanks for the tutorial, but when I checked this method with x
@sarang9756
@sarang9756 3 жыл бұрын
60 is 00111100, if we left shift to 3 places, the first two zeros gets discarded but the 1 is in a place corresponding to 256... That's why you get 480 as answer
@PihFrags
@PihFrags 2 жыл бұрын
Nice tutorial. Greetings from Poland
@ManiSrikumar
@ManiSrikumar 3 жыл бұрын
i am studying in 9 th class ;even i understand easly thanks for amulys academy
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Glad to hear that :)
@nirajraut9408
@nirajraut9408 3 жыл бұрын
@@AmulsAcademy Hey, why do we consider only 8 bits while shifting? What if we consider more bits?
@sanjanasathsarani3573
@sanjanasathsarani3573 11 ай бұрын
thank you very mutch
@EzraRain
@EzraRain 8 ай бұрын
good explantion
@ShaikAbdulFayazYCE
@ShaikAbdulFayazYCE 3 жыл бұрын
What a video no doubt st all even for beginners
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@arindampal4214
@arindampal4214 3 жыл бұрын
Very good explanation.
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@dilanmjayawardena5894
@dilanmjayawardena5894 2 жыл бұрын
this is great
@muhammadriaz6859
@muhammadriaz6859 2 жыл бұрын
thank you miss
@sagarverma9304
@sagarverma9304 2 жыл бұрын
excellent
@anwaralam3136
@anwaralam3136 6 жыл бұрын
i have one more dought which i would like to ask you, from 4 months iam learning python and i learned it well of python basic,suddenly were iam learning the python language they told me to learn C language now so my question is if I learn now C language do i will get confused with these TWO languages between THE PYTHON and C PROGRAMMING language please do let me know please please kindly do let me know .....!!!! THANK YOU...!!
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Don't get confused:) Some concepts are same in both the language just syntax are different. While learning C compare it with python so you will understand the difference and you won't get confused:)
@anwaralam3136
@anwaralam3136 6 жыл бұрын
so you mean to say that i will not get confused, i just have to do comparison with both the language while studying the c language right i have compare c and python while studying the c language...!! thank you..!! THANKS AGAIN..!!!
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Everyone has their own way to learn something. I will do this method it may work for you:)
@manifollowheart
@manifollowheart 5 жыл бұрын
Tq so much you're videos are impressive..😊
@gurjit___sidhu2662
@gurjit___sidhu2662 5 жыл бұрын
Dear Mam , please can you upload videos for sqlite3 in python
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Sorry currently i can't:) @gurjit 777 sidhu
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Thank you:)
@drsmahesan203
@drsmahesan203 3 жыл бұрын
Madam, please note that ~0 = -1 (not 1) ~1 = 0 Python defines ~n for an integer n such that ~n = -(1 + n) or n + ~n = -1 For example, ~20 = -21 and ~-21 = 20, ~0 = -1 , ~1 = -2
@anwaralam3136
@anwaralam3136 6 жыл бұрын
thank you for providing the video of the remaining three bitwise operator but it would have been greate if u had provided the example of negative value also for the bitwise leftshit and the right shift operator. thank you...!!!
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Welcome:) You can try that by yourself :) I have explained how to convert negative value to binary form, then you need to shift the bits and you need add 1 in right shift, you need to add 0's in left shift:) Try this by yourself if you have any doubt you can ask me:)
@anwaralam3136
@anwaralam3136 6 жыл бұрын
thank you for the reply i surely try that with the negative values thank you again...!!!
@Yoosuf_ahamed
@Yoosuf_ahamed Жыл бұрын
Thank you from sl
@AyushiSharmaDSA
@AyushiSharmaDSA 4 жыл бұрын
thank u for the video
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
You're welcome :)
@CharlesDike
@CharlesDike Жыл бұрын
the best!
@saikrishna6296
@saikrishna6296 3 жыл бұрын
What if we get 1 insted of zero can u tell me ~45 is -46 can u please explain me
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
45 = 00101101 ~45 = 11010010 :)
@anamaypatil8804
@anamaypatil8804 11 ай бұрын
can anyone explain how that number 11101011 is -21
@bhaskar_5168
@bhaskar_5168 5 жыл бұрын
clean teaching skills..thanks a lot for teaching simply like a school teacher
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Welcome:)
@anilkumarreddy9349
@anilkumarreddy9349 3 жыл бұрын
I have a dought y your taking 00010100 what the use of left side 3 zeros. 10100 =20
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Here we are representing number using 8 bits 😊
@MauriceWilliams
@MauriceWilliams 3 жыл бұрын
You are a great teacher. I can hear your personality in your voice and I can tell that you're a sweet lady. However I don't quite understand Bitwise Operators yet. Thanks your your effort.
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you so much 😊
@md.golamrabby3000
@md.golamrabby3000 3 жыл бұрын
Thanks a lot
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Pleasure :)
@MrChilo89
@MrChilo89 5 жыл бұрын
Thank you , but at the end how do you technically use the bitwise?
@vikasbharati675
@vikasbharati675 5 жыл бұрын
directly use the bitwise operator
@rajasekharreddy8797
@rajasekharreddy8797 2 жыл бұрын
Extraordinar y. Medam Iam a cse student
@javascriptwar9525
@javascriptwar9525 4 жыл бұрын
Thanyou mam..☺
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Pleasure :)
@hvkhvhk7340
@hvkhvhk7340 2 жыл бұрын
thxx a lotttt
@entertain_free
@entertain_free 4 жыл бұрын
You are good 👍
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Thank you :)
@saibharathi5960
@saibharathi5960 3 жыл бұрын
upto how many shifts we can do?
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
not more than size of integer :)
@manikantagangishetti5972
@manikantagangishetti5972 5 жыл бұрын
we can assign any number or by default we need to take a=20. please help me out.
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
No you can take any value:)
@kanikadua580
@kanikadua580 3 жыл бұрын
Thanks
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Welcome :)
@dev3054
@dev3054 3 жыл бұрын
5:59, when applying bitwise complement to odd numbers, I m not getting the same binary code. Ex: ~21 Ans: -22 Binary for 21 is 00010101 After applying complement it is 11101010, it is equal to -22 Then 22 binary is 00010110 2's complement After flipping 1's complement is 11101001, adding one gives 11101002, it is not the same as ~21 When I am doing for even numbers it is giving the correct answer, why it is wrong when I am doing with an odd number
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
You did mistake in the step, while adding 1 to binary representation of 22. :)
@KhiladiXGaming
@KhiladiXGaming 3 жыл бұрын
202
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Because int is 4 byte and when we take 202 it is represented as 00000000 00000000 00000000 11001010
@labbdogg2929
@labbdogg2929 3 жыл бұрын
It's the way she explained it, I got confused as well, instead of dropping the bits from the left operand i:e after converting 202 to (0b), add 0s to the right of the left operand, in your case add (000) at the end of 202’s (0b) then convert to decimal. Or simply use this formula 202 x 2**3
@lohiths4630
@lohiths4630 3 жыл бұрын
When I tired to check 45 compliment its giving wrong answer
@hasithalakshan5982
@hasithalakshan5982 3 жыл бұрын
realy nice this'🥰
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you! 😊
@hasithalakshan5982
@hasithalakshan5982 3 жыл бұрын
@@AmulsAcademy 😘😘😘😘🧡
@adnanismail9626
@adnanismail9626 4 жыл бұрын
Thank you ... But l miss understanding why (~20 is -21 ) not 235 that is = 11101011
@arpitkesarwani6123
@arpitkesarwani6123 4 жыл бұрын
Am not sure but i think by giving a negation sign for positive no. (20) system will search for binary of negative no.(-21) nd when u will give negation for negative no. System will search for binary of positive no.
@drsmahesan203
@drsmahesan203 3 жыл бұрын
Python defines ~a for an integer a such that a + ~a = -1 or ~a - = - (1 + a). For example, ~0 = -1.; ~20 = -21; ~-21 = 20 etc.
@vandavasievents9281
@vandavasievents9281 3 жыл бұрын
2^4 +2^6 bitwise left then 2^4 how
@venkatgalla45
@venkatgalla45 4 жыл бұрын
thank you,explanation is good
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
My Pleasure :)
@spiralcarbon8658
@spiralcarbon8658 3 жыл бұрын
i wonder those who put dislike on such a tutorial..maybe they are proffesional programmers. To learners like me...i greatly appreciate this tutorial 👏🏻👏🏻👏🏻👏🏻
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you :)
@kartikmehra1391
@kartikmehra1391 4 жыл бұрын
i am sorry mam but i fall in love your work "OKAY" . This word kill me when you say it. OK. OK. OK
@dhruvchaudhary8054
@dhruvchaudhary8054 2 жыл бұрын
print("your voice is sweet")
@sureshrajan7144
@sureshrajan7144 2 жыл бұрын
Why 2power 4 and 2 power 16.that's only confusion
@boopathyraji8851
@boopathyraji8851 4 жыл бұрын
Print("thank you very much")
@paradiseruler9881
@paradiseruler9881 4 жыл бұрын
Sorry! But it's not your coding area .😄
@thecrazygamer7334
@thecrazygamer7334 3 жыл бұрын
Error in line 1
@ahmedelmawrdy4381
@ahmedelmawrdy4381 Жыл бұрын
In line 1 page app.py. Print('thank you ....') ^ Did you mean print()?
@Robocontest-yechimlari
@Robocontest-yechimlari Жыл бұрын
👍👍
@trixion74
@trixion74 2 жыл бұрын
okie
@muthusivaraj7193
@muthusivaraj7193 Жыл бұрын
4:54
@drsmahesan203
@drsmahesan203 3 жыл бұрын
It is confusing when you talk about negative numbers. In Python, if b = -20 b > 2 gives -5 How would you explain this? if c = -2015 c 2 gives -257
@ahmedelmawrdy4381
@ahmedelmawrdy4381 Жыл бұрын
Please could you write the answer on with your own!
@onlinewebsites3476
@onlinewebsites3476 2 жыл бұрын
Why Only Python ?
@ravindranathbedre2588
@ravindranathbedre2588 3 жыл бұрын
❤️❤️
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
😊❤️
@apurvmj
@apurvmj 2 жыл бұрын
Where is it used in real life?
@jaseerhussain2977
@jaseerhussain2977 3 жыл бұрын
madam super
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you very much :)
@drsmahesan203
@drsmahesan203 3 жыл бұрын
It is not right to assume a bit-length for an integer in Python. Python uses variable number of bits depending on the value For example 20 needs 5 bits. bit_legnth method gives the value. a = 20; b=-20 a.bit_length() gives 5 b.bit_legnth() also gives 5 if c = 1025 c.bit_length() gives 11 (-1025).bit_length() also gives 11 d= 10**30 d.bit_length() gives 100 e = 10**40 e.bit_length() gives 133 :-)
@readbhagwatgeeta3810
@readbhagwatgeeta3810 Жыл бұрын
Thanx for your comment...it was very new for me, no one told me that before (specially that bit_length() method)☺️🙏
@mohdriyazuddin9047
@mohdriyazuddin9047 2 жыл бұрын
Mam I'm very week complement topic so plese don't lafaing Mam my qn I 20 binary no 00010100 Than comments using 11101011 this no binary 235 (21 kha se agya ples answer I can not understand)will you explain pls
@tmhr2326
@tmhr2326 4 жыл бұрын
Logic gates ...
@anushkamaddumaarachchi1488
@anushkamaddumaarachchi1488 2 жыл бұрын
I love u
@romasaparov4862
@romasaparov4862 2 жыл бұрын
Ok... Ok... Ok...
@AdityaSingh-lc7pl
@AdityaSingh-lc7pl 4 жыл бұрын
If you know how to convert binary to decimal then check out that 11101011 is not -21.... 🤦😩
@nabeel5765
@nabeel5765 3 жыл бұрын
yes
@This-Is-Vitou
@This-Is-Vitou 4 ай бұрын
Imagine learning python from a kid. me doing it now.
@Goutham-exists
@Goutham-exists 3 ай бұрын
:0 welp same ;-;
@abiryt3552
@abiryt3552 2 жыл бұрын
You are so sweet
@tanupandey1500
@tanupandey1500 2 жыл бұрын
Bhai python bolna shikh lo pyton pyton kiya krti ho
@tnereffidsiemanresuymees8703
@tnereffidsiemanresuymees8703 Жыл бұрын
Hello your computer has virus
@tanveersayyed561
@tanveersayyed561 2 жыл бұрын
dont make small thing more complicated we all ready fedup with half knowledge😡😡😡
@trixion74
@trixion74 2 жыл бұрын
okie