Learn Programming with C++ - 2's Complement

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

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

  • @vaughan4361
    @vaughan4361 3 года назад

    Awesome video! First time I've actually understood the reason for 2's compliment!

  • @alirezasharifan6371
    @alirezasharifan6371 2 года назад

    I appreciate for your videos.
    You took an example about the problem of positive and negative zero, "by supposing negative zero, -1+1= - 0 and then - 0+1=0!!!".
    Even by binary addition, we can't get such a result that negative zero plus one is equal to zero. In binary addition, it would be -1 (1 0 0 0 0 0 0 1).
    Could you please clarify your example?
    And also, while the result of the both columns which you mentioned, is the same (positive one), why asking the computer for zero twice is a problem?

    Thanks for your answer in advance.

    • @VelcodeCS
      @VelcodeCS  2 года назад +1

      In general, it's a matter of realization that if we use the 8th bit as a sign bit, we have two zeros (10000000 & 00000000). So, if we simply count in either direction, we're going to end up in zero twice (with different binary representation). Why is this a problem? The hardware checks if two values are equal by comparing all the bits. If one bit is different, then they are not equal. Hence, -0 and 0 wouldn't be equal. They could modify the hardware to allow this, but modifying the software is simpler. If one mathematical result yields -0 and the other yields 0, it would result in those two results not being equal.

    • @alirezasharifan6371
      @alirezasharifan6371 2 года назад

      @@VelcodeCS I got the point. I'm so grateful for your reply.