C_19 Operators in C - Part 7 (Bitwise Operators-II) | C Programming Tutorials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the series of learning programming in c we are discussing about operators in c in the previous studio i have discussed some bitwise operators three bitwise operators bitwise and bitwiser and bitwise xor operator with the help of proper example so in this video i am going to discuss the remaining bitwise operators that is left shift right shift and bitwise not and bitwise note is also known as one's complement right so we'll be discussing these remaining bitwise operators with the help of proper example and after discussion on these operators i'll be telling you some short trick also like if in a program or if in a code the bitwise operators are given and you are supposed to tell the output send then directly by using that short break you can tell the output of that code right everything will be discussing in this video now and this video is brought to you by an academy so if you are planning to prepare for csir ugc net june 2021 exam then on an academy multiple batches are going on for the complete course for csir net exam june 2021 exam and many batches are going to be started from first of january like one batch is for physical science and one is for mathematical science they are to be started from first of january they'll cover the entire syllabus for those subjects the best faculties will teach you and apart from the classes theory classes some extra classes special classes would also be there like in these classes in those special classes they'll be discussing preparation strategy some shortcuts some tips and tricks and time management skills also and some practice problems also that and that classes would also be helpful for you guys so if you are planning to appear for that exam it's better to start early and this is paid subscription because you will get a complete course structured course for for that csir net exam so this is paid one and if you use the code jkl10 you will get 10 discount on your paid subscription and the classes would be conducted in hindi and notes would be provided to you but notes should be provided to you in english so if you are interested better to get your subscription before price i so all the details the link the subscription subscription link and the link of this course as well as the referral code i will put in the description box of this video you can go and check out so now let us discuss the remaining operators one we have left shift we have right shift and this one is tilt sign this one is bitwise not operator so first let us discuss this left shift operator don't confuse don't get confused in this left shift and right shift see if it is like it is you know right like this this and this so it is left shift this is e this side so it is for right shifting right so this operator is binary operator and if this operator is used to shift the number the given number to left side now what is the syntax of this operator this side we have first operand or you can say variable and the operator and after that you have second operand or the number maybe suppose i am writing here two so this is first operand this is second operand first operand is what you have to shift this variable or you you can say you have to shift this number you have to shift this operand by how many bits that the second operand will tell you by two bits you have to shift this variable this number and to the side left side or here rather than variable or see suppose i am taking this example int a is equal to 10 and i am writing here a left shift 2 and i'm storing suppose this value in c or b now what output you will get what value would be stored in c so now check the functioning of this left shift operator see the value is 10 so bitwise operators always manipulate the data always operate at bit level it is byte all the other operators operates at byte level and this operator manipulate the data or perform the operations at bit level so first of all convert this this is decimal to convert this into binary form i am using 8 bit representation right so now the binary form of this 10 is what we have 1 0 1 0 i hope you know how to convert a decimal number to 2 binary number the shortcut is you can write down here 1 2 4 8 16 32 64 128 and i am placing 1 and 1 here because 8 plus 2 is 10 so this is binary form of 10 right now if suppose number is 11 then where you will put 1 here 1 here 1 as well as here 1 8 plus 2 is 10 plus 1 is 11 right this is short cut so now you have to shift this number by 2 bits left shift means this side so now after left shifting the number would become something like this this side left shift you have to shift this means one and two two bits would be discarded right now this bit would be at this place this would be shifted to this like this and now these two places are remaining blank because we have discarded two bits from the left now at this places the trailing places the trailing bits would be filled with zero zero and 0. it's not like that we are filling these 0 and 0 here no these bits are discarded no use of these bits just fill the remaining the trailing places the trailing bits with 0. now this is the new number now convert this into decimal what output you will get this is binary form right now the decimal form of this one we have 1 at this place 8 and we have 1 at this place 32 32 plus 8 is 40. so this number is 40 when you convert this into my decimal that you will get 40. so now in c what value would be stored 40 so if you will print c then you will get 40 right now and if you print a also then after that a has also updated and that is also 40. or you can tell me if i am wrong just write down a simple program take a variable left shift this print both c and a what output you will get you can tell me in common box right so this is functioning of left shift operator i hope you got it suppose i shift this one by ah four a left shift four now what you will get four bits would be shifted to left these four bit one two three four these bits would be discarded now this one would be at this place one zero one zero the remaining bits the trailing bits should be filled with zero zero zero right now what is the decimal number of this one we have 1 at 128 and we have 1 at where 32 so just add these numbers this is i guess one six 160 so the output would be 160 the decimal one number corresponding to this is 160. now this is the processor long processor now what is the shortcut if without look without converting it into binary and without shifting how you can tell see if a left shift 4 then final output you will get is what the number a just take the number that is 10 into 2 raised to power the right operand this is left operand to this operator this is right operand so here at in right operand we have what 4 2 raise to the power 4 now 10 into 2 raise to power 4 is 16 so that is what 160 and that that's it we got 160. so this is shortcut if you write here 2 what output you will get without looking at this one a is 10 into 2 raised to the power 2 10 into 4 that is 40 and the same output we got 40 so this is short short trick to find out the answer to to find out the output right without following the proper processor now what about left sorry right shift operator this is used to shift the the number by two right side so this is this one it is also having two operand one is this one one is this one this is the number you have to shift this is by how many bits you have to shift that number so suppose i'm taking same example a is 10 binary value of a is this one i'm going to do what right shift of this by two now what is the processor see right shift this number means this side you have to shift this side so now two bits one and two these two bits would be discarded now this bit would be at this place and now here we have blank spaces so in this case the leading space the leading places would be filled with zero same here 0 it's not like that we discard it and this would be at this side we discard it or you can say we we remove this this bit from here and we place it here no these bits should be discarded 2 bits and we place new bits that is zero we fill this remaining space the blank space with zeros now see what is decimal form of this one we have one at what place this is what two so the decimal form of this is 2 now suppose if you shift it by 4 right shift by 4 then what value you will get this number y 4 1 2 3 4 these 4 bits would be discarded now these bits would be shifted like this 0 0 0 0 and that the remaining places will fill 0 so what is decimal form of this one 0 because we have no 1 no 1 here so that is 0 output would be 0. now let us discuss the shortcut to find out the shift the result after the shift operator without following the proper processor see the number is a that is 10 if you right shift this one then you divide this in left shift we multiply this number the given number so 10 divided by 2 raised to power how many bits are there 2 raise to power 4. so 10 divided by 16. so definitely the output would be 0 0 point something so it will take it will remove that fractional part it will take only decimal value if i write here that's what exactly you got 2 now if you write here 2 then what out you will get 10 divided by 2 raised to power 2 10 divided by 4 that is we get 2 2 point something but it will remove that fractional part it will give you what that decimal value and exactly we got 2 so this is what shortcut so i hope you got what our left shift and right shift operator and you can tell the output by using the short short trick now what about this logical not operator so this operator will use to find out you can see the ones complement of the number or this will invert the bits in what the bits mean if the bit is zero original bit is zero after applying this operator that will become one if the original bit is one after applying this operation that become zero see let us take one example if i write here um that number 5 right and or you can say int a is equal to 5 and i am storing b is equal to bitwise not a now what output would you you will get means what is the value of b now see first of all convert this into binary the binary number is this one one zero one i'm using four bits for this five because remaining would be zero zero so one two four eight four plus one is five so this is what binary number of 5 now bit wise not of a so the bits would be converted inverted means 1 becomes 0 this becomes 1 this becomes 0 this become 1 right so this is what binary number of 10 so this is when you apply ah bitwise node then this output you will get or when you will run this one into computer then you will get a negative number means you will get a two's complement number here negative numbers in computer negative numbers are stored uh using three methods we can store negative numbers sign magnitude ones complement and two's complement but in sign magnitude and once complements there are some drawbacks that is why uh the standard method to represent to store negative numbers in computer memory is two's complement that maybe we will be discussing in some separate video that is a complete chapter right now what output you will get when you run this statement into your computer you will get what ah that negative number now see negative number what you will get see this is the number suppose a and when you apply negation of a then shortcut is what how you will get minus a plus 1 just simply do this thing and you will get that answer means minus a is what 5 5 5 plus 1 is 6 that minus 6 you will get so according to the logic of bitwise not operator this is also right you will get this one but in computer memory you will get this one in 2's complement form so that is also fine now suppose a is 10 and so negation of a would become minus 10 plus 1 that is minus 11 you will get right so i hope directly you can uh tell the output if this this is given so now minus 10 would be stored in b fine now this is what about bit wise not operator and see bit wise it's not like that you can only use variable here you can also write simply negation of 5 then also you'll get same output negation of 10 you can also use a constant that is also fine right and suppose if you use in that left shift and right shift also you can write down five left shift one that is also fine means here please don't get confused this is what the number you have to shift means 5 need to be converted into binary and that number need to shift by how many bits that will tell the right operand by 1 bit or you can write down like 10 10 right shift 2 this is also fine you can also use constant instead of variables or here also you can use some that arithmetic operations or let us suppose if i write like this a is ten suppose a is ten i am writing a plus one left shift two and i am writing a plus two right shift one or i am writing negation of a plus 3 now tell me what you can tell me in comment box what would be output of these things or maybe there are some errors like you cannot use these kind of things in these operators then also you can tell me right so you have to execute these statements fine so now this is all about bitwise operators i mean i just want to give you the overview the functioning of these operators we'll be discussing in separate video maybe some technical type of questions that could be asked on these operators some twister type of questions right so now that's it for this video now in next video i'll be discussing about some special operators in c so now i'll see in the next video till then bye you
Info
Channel: Jenny's lectures CS/IT NET&JRF
Views: 27,827
Rating: 4.9487181 out of 5
Keywords: data structure tutorials, operating system, data structure and algorithms, jayanti khatri lamba, jennys lectures, jenny data structures, jennys lectures DS, jenny lamba, jennys baby, jennys lectures baby, data structures
Id: LP0acaj3ZLE
Channel Id: undefined
Length: 19min 49sec (1189 seconds)
Published: Mon Dec 28 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.