0

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.

AlanSTACK
  • 5,525
  • 3
  • 40
  • 99
  • I wonder how you convert a positive number to 2's compliment when it does not fit into the bits. E.g. for a 16 bit machine how you calculate 65535-65534? – user3528438 Apr 17 '16 at 20:06
  • @user3528438 A 16-bit machine can easily work with 192-bit numbers if desired - the adder is *also* built out of a sequence of repeating parts, you can do the same thing in software. Basically, you "wire" the two together while handling the carry/borrow properly and you can extend the effective width of the adder as much as you want. 8-bit machines dealt with 16-bit numbers all the time - it's not like 8-bit numbers are very useful. – Luaan Apr 17 '16 at 21:06

1 Answers1

1

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.

Luaan
  • 62,244
  • 7
  • 97
  • 116