mathbinarynotation

Is there an easy way to implement binary arithmetic without 2's compliment?


As a beginner computer science student, please excuse my limited knowledge of the field.

Initially, we learned how to perform the following basic binary arithmetic manually.

  1. How to do addition with binary numbers

  2. How to do subtraction with binary numbers

However, even as a novice programmer, I realized that the methods we learned by hand are challenging to translate into computer code algorithms example. Maybe this is just a personal perception.

Later, we studied 2's complement, which made things a bit easier (e.g., negative numbers were simpler to implement and subtraction was now just the addition of negative numbers).

My question is, was there a way to perform all arithmetic operations (multiplication, division, addition, and subtraction) without using 2's complement? Or was the invention of 2's complement solely for this purpose? This is a purely pedagogical exercise.


Solution

  • 2's complement works great. What exactly would you want to improve? It can deal with arbitrarily large numbers, and only uses a chain of very simple processing units to do its job.

    The main exception is with floating point numbers, which don't use 2's complement. I'm sure you'll learn about IEEE-754 soon, it's a lot of fun :)

    Finally, noöne is forcing you to use 2's complement. You can do whatever you want, it's just that 2's is great and cheap. You can make your software calculate everything in Roman numerals if you so desire. It's not going to be very fast, though.