#15 Python Tutorial for Beginners | Python BitWise Operators
Video Title: #15 Python Tutorial for Beginners | Python BitWise Operators
Welcome back aliens my name is Ivan 20 and let’s give you this series on Python so till this point we have worked with operators right we have talked about assignment operator I panic operators and logical operators now it’s time to focus on some hold operators and this
Time we are going to work with bitwise now if remember in one of the video we have talked about money formats right so this is where you will use them so far should the names suggest it is something you do with money formats right so what
Am I going to do now is with bits so let’s get started so it’s open Python and let’s do this calculation now the first one so if you talk about bitwise we have six different operators we have complement operator then we have and all XOR left shift and right shift again
Let’s talk the first one we just bombed them interpreter and if you look at this symbol of it it’s weird right if we don’t use this symbol match so this is called as tilde operator all till the operator now when you will find it so if
You look at your keyboard just below the Escape key you have this special key call s tilde so let’s use it and that’s your tilde sign and will give any number here we will go for 12 now when you say enter what you are expecting come on Google for line of
Guess here maybe March 12 or maybe minus one something like that right now if I say enter oh we got minus 13 that’s weird why minus 13 so let’s do a research on this now so if we go back to my paint and let’s do the calculation so
How do you find this now to understand this first of all we need to find what is complement means now when you say complement it will simply do ripples of your bunny from an example if you say complement one it will give you zero and if you say
Complement zero it will give you one that’s what he’s doing now the same thing is applied on 12 right now and what is 12 12 is actually if you convert two into body format you will get this so you will get four zeros double one double zero that’s your 12
And a format and I love this mobile phone model right no Caleb I wonder 1 0 everyone loved it now we need to find a complement of it right so you have to find the complement of it so what you will do is you will reverse the number so this this 0
Becomes 1 and then this is 1 then this is 0 0 1 1 1 one so this is your complement of 12 but hold on what is this number and why we got minus 13 that’s weird right now if you look at minus 30 in Y minus 13 is
This number that you have to find out that now now to understand this concept again as a programmer you need to know all this concept because even balance so when you do any course in for I T or CS this is what they will teach you in the
First year but if you have if you don’t know this concept that’s okay you can learn here now now we have a concept of two’s complement because what happens is in your system we can store positive numbers right we can store 12 we can
Store 13 we can store 15 20 21 or maybe 1000 but how to store negative numbers not the store negative numbers we first of all pick to be don’t store negative numbers in the system we always tell positive numbers so even if you want to store this minus 13 you need to convert
This number into positive number first and the way you can do that is with the help of two’s complement now how do you find two’s complement so to find two’s complement we need to find ones complement plus one this is the formula okay so when is a two’s
Complement it is ones complement plus one now how do you find ones complement it’s easy actually first convert this number into one a format now it is studied it’s 12 0 0 0 0 1 1 0 1 this is a bunny format of plus 13 so this is
Studied ok we want to find – and in writes I have to find two’s complement of this number now let’s find the – complement and how do you find ones complement it’s easy now we know how to find complement right so we have to reverse this number so you don’t get 1 1
1 1 0 0 1 0 so this is one’s complement of 13 but we want to find two’s complement right so what you will do you will say plus 1 now this is so when you say 0 plus 1 it will give you 1 and then
We got 1 then regards 0 0 1 1 1 1 now this number here this is minus 13 okay so this is two’s complement of 13 which is mastered in we got it and now if you compare this number with compliments of 12 they are same and that’s why you got
So when you say complements oft well you got mastered in right so that was the answer so that’s how you can work with complement so when you want to store a number this to do now I would recommend you to try different numbers here maybe maybe compliments or 45 maybe compliments of
121 so try it out and let’s let’s see what answers you get there so that’s your compliments operator the next one we have is bitwise and now if you remember in the previous video we have talked about logical operators right so in logical we have and and
Alright so here as well we can use bitwise and and bitwise all so in and remember this thing so anyway you have and and if you have two conditions one and both are true then only you will get true and in odd if you have at least one
True you will get true if you remember so if you remember this table right that’s what you’re going to do here now so let’s do bitwise and now which operator we use here so we don’t use any because a and D and is for logical operations so here we have to use
Ampersand symbol so let’s take 12 am person 13 okay so we got this two numbers 12 and 13 if I say enter you got 12 but why 12 so let’s find out using bitwise so let’s go back to our paint and here will convert 12 into panel
Format which is 0 0 0 0 1 1 double Z this is 12 binary format right and then we have produced by this format which is 0 0 0 0 1 1 0 1 and now we need to find out the bitwise here right so we have to
Work with bits so let’s compare this bit with this bit now if you remember and operation if both are 1 then only 1 right so this in this case this is 0 1 so it will be 0 this is 0 this is 1 this is 1 because both of once and then we
Got 0 0 0 0 and if you compare this output this is 12 right so you got B twice and so this was and and operation and that’s why you got 12 let’s do all so it’s a 12 all so now for all we have
To use pipe ok so forth and we have am person for all we have pipe and then okay where you will find pipes I twist B it is above your Enter button so it is a 12 or 13 come on yes now in fact before entering here let’s do calculations
Let’s compare here so let’s go back here and let’s do a compare let’s do some calculation so it will be 0 0 0 0 1 1 w that’s 1200 0 0 1 1 0 1 that is your 30 in void and let’s do all so when you say
All if any one is one so so your output is 1 byte so we got one we got 0 1 1 0 0 0 0 and that’s your 13 right so this is 13 let’s verify and if I say enter oh we quite ready in right so this works so
This is how you work with bitwise and and bitwise or internal you know you might be thinking or the 12 and 10 you will get maybe some other number let’s try so it’s a 25 and maybe 31 or maybe 30 yeah 30 and you can see we got 24
Again this is your homework right so try it on your notebook so put your notebook and convoy 25 do binary format converted into binary format and just do and operation and of course you will get only for the next one we have is X all now in X or watch
It I switch this it’s actually very simple when you say you have two numbers which is 0 and 0 now since we don’t have any one here we will get 0 then you have 0 1 now in this case you have odd number
Of 1 right so which is 1 1 so you will get answer 1 now when you say 1 and 0 so we again we have odd numbers of 1 which is 1 and when you have when you don’t have odd numbers of 1 you can see we have 2 ones
Which is even number so you will get 0 ok so when you have odd numbers of one you will get one if form do remember in a shortcut way it’s very simple if both the numbers are different then you can go for one right so we have 0 1 is 1 1 0
Is 1 so that’s very simple this is how you perform X order patient this is X or and you can represent that with the help of CAP simple so let’s do that here how can we take two different numbers here we will go for let’s go for 12 again the same number 12
Cap 13 here oh that just made a mistake there 12 cap 13 and you can see the answer is 1 but why can’t let’s verify so let’s go back to the go back here and do calculations so what is 12 we have done that 0 0 0 0
1 1 double zero and then we have put in here which is 0 0 0 0 1 1 0 1 and now let’s do X or so if you have two different numbers than 1 right so they’re different one they are same 0 0 0 all are same
So we’ll go for zero zero zero so the only answer you got here is one right so that’s why we got one that’s how you perform XOR operation so you can try here with different numbers right again the same number 25 and Teddy dries out
And let’s see what what you get in fact I will do it here so I will say X 25 cap 30 and you’ve got seven but how seven that’s your homework right I’ll it mean in the comment section what you get here now once you have done with and or and
XOR let’s move towards left shift I love this concept of left shift so what is left shift here so what I will do is first of all let me try something else I would say then now when you say left shift you have to use this left shift operators which is
Another left-hand side and then you will say – okay what’s your guess what is the output I don’t know let’s try so you got 40 but why 40 let’s find out now when you say let’s go to paint here and let’s do calculation now when you say 10 what is 10 now I
Will go for I will ignore the fat here zeros okay so just because I am damn lazy to write every time that I would hardly go with one zero one zero so again we have we do have force it was before but ignore them so we got one
Zero one zero and then we have to apply a left shift operator here now how do we use it now in some shape – what happens is imagine there is a box here so imagine there’s a this is a box and then we have a dot here dot symbol and then
We have some zeros now of course right every numbers represent this for example when you say 5 it’s actually five point zero in fact we can have multiple zero zero right so you said 65 it’s a again we do have zeros there but we ignore zeros because there are zeros here as
Well when you say one zero one zero we do have a dot so we do have a dot and then after that we have multiple zeros in left shift what we do is we shift the bits on left hand side get enough for which side you are so so you are facing
Me so for you this side right so left hand side so let’s do that okay so now so when you said left shift you have to shift bits but how many bits you need to shift two bits right example if you see the output here so you have shifting ten by two bits
So when you say two bits you got 1 0 1 0 and then you need to shift on left hand side 2 bits so you you will add two more zeros then we have a dot so we were having a dot after 0 after shifting you have shifted two
Zeros on this side right now this number here is 40 now how do you verify go with a normal calculation right 2002’s 2 1 2 is to 2 is to 3 so this 1 is to 3 and then we got to H to 4 and then we go out
To a so fine so consider this one and consider this one so this is 32 and this is 8 so try to place 8 is 40 right so we got the answer so that’s how you find left shift how about right shape it’s very simple so we also have a positive right shift
Right what I will do is I will say over the same number 10 and right shift with 2 bits now in left shift if you are gaining bits in right shape you’re losing bits that’s what you find so if I say enter you can say we got to but why
Do let’s do it again let’s do it here so we have 1 0 1 0 s then so we have it we have a dot here so in right shift you shift on this side right right-hand side so you will be losing how many 2 bits right so you’ll be losing these 2
Bits so what is remaining is 1 0 which is this is remaining right and what is 1 0 H 2 right and that’s why we got 2 so that’s how you work with left shift and right shift so that’s your bitwise operator so we have talked about complement we have
Talked about and all X or and left shift and right shift so again even when you do scientific calculation this will be useful there so I hope you are enjoying this is written in the comment section if you if you need some more improvement let me know on which topic so that’s it
Everyone you
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
Hello.. could anyone please answer to my question. binary format of 12 is 1100. why he added 0000 before 1100?
I have a question, as per binary format , 12 :- 1100 ( how u got 00001100). This is very confusing. i had checked you other binary format video as per that it also says the same.. kindly help to understand the same.
aliens!
i think its better if you start with binary format first
❤❤❤❤❤❤❤
once i learned to compare them vertically it made a lot more sense.
Sir will say compliment of 13 and 14 binary is differ from 13 binary number will you please explain
25 ^ 30 is giving 7 and 25^13 is giving different answer ?? not clear here, could you pls explain
Thank you so much sir😢
Your python tutorial is too good I just love it ☺️🎉
Sir Your a gift from Heaven!
why bin(13) is 00001101 instead of 1101, didn't understand that part
guys why I can't get -24 from 23 the 2's complement of 24 is 111100111 then I plus 1 to complement and I get 111100112 and the -24 is 111101000 wth is that or I missed something i don't know every number works but this one doesn't idk. Can someone explain it to me
Hence the system can't store negative which is -13 so it'll store it as positive number as 12. Right?
a beginner from 2024 . Thank u sir 🙏♥️
But sir if we put ~1 it gives -2
while adding two's complement with 1, how to add 1 with 1?
why four zeros before the binary numbers of 12 and 13?
you are a fantastic it expert
This is a fantastic resource. I only have one feedback. Please slow down a little. Sometimes you speak too fast. Great channel and all the best
I was learning python and there is no tilde key in my 60% keyboard xD had to use OSK for tilde xD and the content is very good, i am hoping to clear some tech interviews of python in the future month.
25&30 = 24. Bitwise & cus 25/30 000011000 and binary of 24 gives 1110001
binary number of 13 I got only 1101. I don't know how you get 00001101. can you explain
now my book is crystal clear.I can understand Bitwise Operators. Thanks a lot
Thank you Sir.
It was really helpful.
~n=-n-1
In this question 25^30 How to answer is 7 can anyone tell me?
But when we do ~1 in system it gives -2 it supposed to be 0 ryt
Sir,why you put four zero in starting?
ie: 00001100
Plz reply
Why we are using 12 as 00001100 but not simply as 1100
you deserve an award
12 binary is 1100 so how come 00001100😢 please explain it
Nice
10th October 2023
Excellent the way and methods by which you have taught the operators in python it helped easy grasping and implementation of the basics👌. Just awesome, love the way you teach❤
sir, 12 bin is 1100
i think i'm right
your video is outstanding. I am from Bangladesh
25 ^ 30 = 7
We should convert obtained binary into normal number
why using binary of 12 as 00001100 when it is 1100
25^30 =7
how is int value of '11110011' (-13)?
why are you takeing 4 zero in binary format 0000 1100
But for exam we need proper program sir so pls compile in new file sir 😢 but I r excellent professor😊
You are a very good teacher.
25^30=000000111
Because bin (7)is 111
After watching this video, i have 1 doubt.
After solving left shift of 10 & 2, we got ans as 40. you only used binary format of 10 but what about 2?
I'm enjoying your free course and it's worth effective. It would be very nice if someone clarifies my doubt
Sir if we a negative number in compliment what happens