Need expert helpâ€”fast? Use the Help Bell for personalized assistance getting answers to your important questions.

A long time ago when I was at college,

I vaguely remember that computers do all there multiplications and division by adding and subtraction, or it was the other way round. I have searched the net and cannot found anything about it.

Could anybody explain how it is done, preferrable with some examples.

Thanks

Jetforce

I vaguely remember that computers do all there multiplications and division by adding and subtraction, or it was the other way round. I have searched the net and cannot found anything about it.

Could anybody explain how it is done, preferrable with some examples.

Thanks

Jetforce

http://computer.howstuffworks.com/boolean.htm

And Electric gates:

http://electronics.howstuffworks.com/digital-electronics.htm

Good luck,

[r.D]

All computers do their arithmetic through addition. For subtraction, 1's complement is performed and so on. To know in detail about this you can read any book on logic design. Your question is a subject by itself in Computer Science Engineering.

:)

http://www.andraka.com/multipli.htm

The sites above seem to be about the math involved rather than the actual way in which the processors ALU works.

As you pointed, computers do arithemtics by using basic binary operations provided by available electronic circuits.

Here is a simple overview over those layers of basic operations, the way _computers_ do it. An operation in the next levels is accomplished by combining operations of the previous layers.

1 - binary AND, binary NOT - these two operations are enough to do all of the arithmetics

so the really basic operation is not addition etc, but simplest logic

x NOT x

- -------

0 1

1 0

x y x AND y

--- ---------

0 0 0

0 1 0

1 0 0

1 1 0

2 - binary addition, binary multiplication 2 ("shifting bits left") or division by 2 ("shifting bits right")

therefore you can say "it's adding and multiplying by 2"

binary addition: 0101 + 0011 = 1000 (5 + 3 = 8)

multiplication by 2: 0101 << 1 = 1010 (5 * 2 = 10) (read: shift left by 1)

division by 2: 1000 >> 1 = 0100 (8 / 2 = 4) (read: shift right by 1)

3 - further unsigned (greater or equal 0) integer operations

* subtraction is addition of the 2's complement:

x - y = (x + (C - y)) - C with C = 2^number of bits

this "C - y" is the 2's complement of y and can be calculated by inverting all bits (NOT operation) and adding 1:

to continue 4-bit examples: C = 2^4 = 16, so x - y = x + ("16" - y) + "16" when using 4 bits

0101 (5) gives 1011 ("-5"), so it is "-5" = 11

0011 (3) gives 1101 ("-3"), so it is "-3" = 13

8 - 3 = 5 is calculated as (8 + ("-3")) - 16 = 8 + 13 - 16 = 5

this - 16 happens automatically by non-existence of a 5th bit

1000 - 0011 = 1000 + 1101 = 0101

* multiplication is a combination of multiplication by 2 and addition:

x * 10 is calculated as (x * 2 * 2 + x) * 2 = (x * 4 + x) * 2 = x * 5 * 5 = x * 10

* integer division is carried out in a similar way

x / 10 = (x / 2) / 5 = ((x / 2) - 5) / 2 / 2

x / 3 = (x - 3) / 2

example: 8 / 3 = 2

1000 / 0011 = (1000 - 0011) >> 1 = 0101 >> 1 = 0010

4 - signed integer (negative and non-negative) are representes as 2's complement, and the operations reduce to the operations above. special handling of "sign", "overflow" and "carry" is added.

example. -5 + 8 = 3

1011 + 1000 = 0011

5 - higer level integer operations like power or logarithm require a bit more complicated calculation - they are carried out using operations from previous levels.

x^2 = x * x

x^3 = x^2 * x

x^4 = x^2 * x^2

etc.

6 - "floating point" operations are reduced to integer operations where the position of decimal point is calculated parallel to basic operation:

3.5 + 2.5 = 6 can be represented as 011.1 + 010.1 = 110.0

that is (7/2) + (5/2) = (12/2), we calculate 3.5 + 2.5 the same way as 7 + 5

7 - transcedental functions as sine, cosine etc. are (partially) estimated using built-in tables, because that is much faster than algorithmic computation

example: for sinus function, only 1/4 of the full period (that is 0 to PI/2) needs to be present in the lookup table, because:

sin(x) = sin(PI/2 - x)

example: for cosinus, sinus is used, because cos(x) = sin(x + PI/2)

etc.

8 - you'r software starts here, it's up to you how you will do it :-)

cheers,

georg

x y x XOR y

--- ---------

0 0 0

0 1 1

1 0 1

1 1 0 (and generate a carry)

in the terms of the algebra, yes.

but when talking about real circuits (and real computers),

THE real basic operation is NAND(x, y) = NOT(x AND y).

this is because it requires just a single transistor and it is

enough to build every other operation, i.e. the whole logic.

x y x NAND y

- - -----------

0 0 1

0 1 1

1 0 1

1 1 0

actually, the XOR operation is composed out of four NAND operations, for example in following way:

a = x NAND y (gate 1)

b = a NAND x (gate 2)

c = a NAND y (gate 3)

d = b NAND c = x XOR y (gate 4)

i.e. x XOR y = NOT{NOT[NOT(x AND y) AND x] AND NOT[NOT(x AND y) AND y]}

(with the given technique, it is not possible to produce XOR operation with less than 4 transistors;

ADD operation requires about 16 transistors)

cheers,

georg

PS: one more correction to the above:

x * 10 is calculated as (x * 2 * 2 + x) * 2 = (x * 4 + x) * 2 = x * 5 * 2 = x * 10

you asked about "how computers do arithmetic",

but you accepted an answer providing information about binary arithmetics

(which is just the theoretical base for how computers do arithmetics).

can you please explain your decision?

g.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

Hope these can help

http://www.evergreen.edu/biophysics/technotes/misc/bin_math.htm

http://www.swarthmore.edu/NatSci/echeeve1/Ref/BinaryMath/BinaryMath.html

BC