Bitwise Right Shift Operator in Python

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024

Комментарии • 22

  • @sinhalaigenumawithashokabandar
    @sinhalaigenumawithashokabandar Месяц назад

    nice to heard this types of history data of our country. Thanks

  • @rajeshprajapati1851
    @rajeshprajapati1851 Год назад +1

    He has already done a great work in C language and now this.

  • @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

  • @intelinside1473
    @intelinside1473 7 месяцев назад +3

    >>> a=-12
    >>> bin(a)
    '-0b1100'
    But in video 8:36
    10100 = -12?
    Can anyone explain that pleace?

    • @big-jo89
      @big-jo89 5 месяцев назад +3

      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.

  • @TribhuvanMahath
    @TribhuvanMahath 11 месяцев назад

    Thanks

  • @Ranganadhamkrishnachaitanya27
    @Ranganadhamkrishnachaitanya27 Год назад

    Nice explanation bro could please do SQL entire topic please brother

  • @satishgokul7176
    @satishgokul7176 11 месяцев назад +3

    @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 10 месяцев назад +1

      Yes I also feel the same

    • @big-jo89
      @big-jo89 8 месяцев назад +1

      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 5 месяцев назад

      ⁠@@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 5 месяцев назад

      @@vonSmash
      sorry but I didn't get what you mean

    • @vonSmash
      @vonSmash 5 месяцев назад +1

      ​@@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 😅

  • @markuche1337
    @markuche1337 Год назад

    Awesome explanation thanks ❤

  • @user-iq8ll9op2y
    @user-iq8ll9op2y 2 месяца назад

    it is working odd num or not?

  • @harshitha8394
    @harshitha8394 Месяц назад +1

    how we got a>>1 as 11010, where a = -12

    • @akramshaik5019
      @akramshaik5019 Месяц назад

      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

  • @Med2402
    @Med2402 Месяц назад

    from the negative number part it's not very clear

  • @majjiharish4165
    @majjiharish4165 Год назад

    upload in module and error concept

  • @rajisam4802
    @rajisam4802 7 месяцев назад

    if the division results in float values what should be the result??