Bitwise Right Shift Operator in Python

  Рет қаралды 45,359

Neso Academy

Neso Academy

Күн бұрын

Пікірлер: 24
@rajeshprajapati1851
@rajeshprajapati1851 Жыл бұрын
He has already done a great work in C language and now this.
@intelinside1473
@intelinside1473 Жыл бұрын
>>> a=-12 >>> bin(a) '-0b1100' But in video 8:36 10100 = -12? Can anyone explain that pleace?
@big-jo89
@big-jo89 10 ай бұрын
because when you use the bin() function in Python to represent a negative integer, it returns the binary representation of the positive magnitude of that number, but with a leading '-' sign to indicate that it's a negative number of the same positive number. for example number 12 if we run >>> bin ( 12 ) it return '0b1100' == the binary representation of the positive 12 but when we run >>> bin ( - 12 ) it return '-0b1100' == the negative representation of the positive 12 but not in the actual binary representation of ( -12 ) which is '0b 1111 0100' I guess python choose to represents negative integers using two's complement notation is to maintain consistency and simplicity in its representation of integers, as this approach aligns with how integers are typically represented and manipulated in computer systems.
@sinhalaigenumawithashokabandar
@sinhalaigenumawithashokabandar 6 ай бұрын
nice to heard this types of history data of our country. Thanks
@li0770
@li0770 Жыл бұрын
Thanks a lot. I hope you could explain about passing function as arguments of another function without including the parentheses, it's a tough topic for me
@markuche1337
@markuche1337 Жыл бұрын
Awesome explanation thanks ❤
@Ranganadhamkrishnachaitanya27
@Ranganadhamkrishnachaitanya27 Жыл бұрын
Nice explanation bro could please do SQL entire topic please brother
@TribhuvanMahath
@TribhuvanMahath Жыл бұрын
Thanks
@satishgokul7176
@satishgokul7176 Жыл бұрын
@9:06 didn't understood how the shift occurs it should be 01010 instead 11010. please anyone correct me if i was wrong
@pmalik1975
@pmalik1975 Жыл бұрын
Yes I also feel the same
@big-jo89
@big-jo89 Жыл бұрын
because the leftmost bit indicates the sign (0 for positive, 1 for negative) in a 2's complement system. so you shift the actual bits not the bit which represent the number's sign. in this case, 1 is the most left bit which means that the number is negative. so for systems and compilers to differentiate between positive and negative number they put 0 or 1 in front of the binary to indicate its sign for the hardware can then work with them
@vonSmash
@vonSmash 10 ай бұрын
⁠@@big-jo89​​⁠​⁠​⁠​⁠yeah that’s true. My confusion though is that I thought that after the 2nd shift the binary would be 10101 not 11101. Because if we remove the sign number for a second, after the first shift we had 1010, right? Then if we shift it a second time it should be 0101, no? Or what am I missing? 😅
@big-jo89
@big-jo89 10 ай бұрын
@@vonSmash sorry but I didn't get what you mean
@vonSmash
@vonSmash 10 ай бұрын
​@@big-jo89 Yeah, I see that my question was a big badly formulated.. 😄 haha! let me try again. At 04:00 we first see him explaining the shift of the positive number 12 which is equal to 01100. If we just remove the sign number 0 here to make it a bit clearer then we have 1100, right? He then shows the first shift which goes from 1100 to 0110, and this makes sense to me because it looks like the 0 that was all the way to the right has now moved to the start on the left. Then the second moves is like I expected too, from 0110 to 0011. However, my confusion starts at 09:03 when he shows the negative numer, -12 = 10100 (remove the sign and we have 0100). Because when he show the first shift it goes from 0100 to 1010. Where did that extra 1 come from? And the same in the second shift, from 1010 to 1101. There is now three 1's. It feels like I've missed an explanation from him in the video but even after rewatching I can't understand it. Does my confusion make sense, and can you see what I'm getting wrong? Maybe my assumption is wrong form the start but don't know what I should assume otherwise 😅
@VengataGaneshan-z1x
@VengataGaneshan-z1x 7 ай бұрын
it is working odd num or not?
@ShilpaS-z5x
@ShilpaS-z5x 4 ай бұрын
If the binary of -12 is 10100, then a>>1 is 10010 right ? Can anyone explain this part?
@MaddiLethi
@MaddiLethi 2 ай бұрын
11010 Sin value remains same
@Med2402
@Med2402 6 ай бұрын
from the negative number part it's not very clear
@harshitha8394
@harshitha8394 6 ай бұрын
how we got a>>1 as 11010, where a = -12
@akramshaik5019
@akramshaik5019 6 ай бұрын
When do the right shift to the positive number for example : a=12 it's binary equivalent number is 01100 if a>>1 is used it becomes 00110 like u can see after shifting to the left side from the tens place we are getting 0's as it is a positive number and similarly we get 1 for the negative numbers as its binary representation is 1 so for a=-12 binary: 10100,a>>1 we get 11010....this is what I understood hope u find it helpful
@majjiharish4165
@majjiharish4165 Жыл бұрын
upload in module and error concept
@rajisam4802
@rajisam4802 Жыл бұрын
if the division results in float values what should be the result??
Bitwise Left Shift Operator in Python
6:52
Neso Academy
Рет қаралды 27 М.
Operators in Python | Bitwise Operators | Python Tutorials for Beginners #lec17
17:11
Bitwise Operators and WHY we use them
8:41
Alex Hyett
Рет қаралды 102 М.
“typing” is getting deprecated in Python
7:20
Indently
Рет қаралды 82 М.
C bitwise operators 🔣
6:47
Bro Code
Рет қаралды 111 М.
Bitwise Operators in Python (Part 1)
9:21
Neso Academy
Рет қаралды 53 М.
AsyncIO, await, and async - Concurrency in Python
9:12
Socratica
Рет қаралды 122 М.
#14 Python Tutorial for Beginners | Python BitWise Operators
12:42
Lecture 1: Introduction to CS and Programming Using Python
1:03:30
MIT OpenCourseWare
Рет қаралды 1 МЛН