What do adding, subtracting, multiplying and dividing do for a computer? Or, how does a computer use them?
K J
2010-01-31 12:02:51 UTC
I know the calculator application uses them, but I think that a computer also uses them for general operation. Am I right? Does a computer use math to run a program; save something; boot an operating system? And if it does, do you know how?
Four answers:
peteams
2010-02-01 11:53:00 UTC
Computers are work by constructing what could be termed a mathematical model of the world with data occasional travelling from the real world to the model and viceversa. This model is constructed not only of the operators we know from school, but from many others including Boolean operators and set operators.
The most common use of addition and multiplication is in operations finding the address of an object. The individual bytes that comprise a PCs memory can be viewed as being accessed by an integer. Objects held within the memory may occupy a group of contiguous bytes. Where several similar objects are held together they may be index by a small integer, this is typically called an "array" of objects. So to get the address of object N, you multiple N by the size of the objects in bytes and add to that the address of the first object.
Much as subtraction is the reverse of addition and division is the reverse of multiplication, if you know the address of an object and you want to know its position in an array you do the reverse of the above. You subtract the address of the first object from the address of the known object and then you divide by the size of the objects.
Tony
2010-01-31 21:21:49 UTC
Yes. Everything inside the computer is just numbers, the computer does not understand anything it self, it just follows extremely long sequences of instructions that are themselves simply numbers.
The computers memory is a sequence of numbers and each number is itself numbered so that the CPU can find it.
The CPU contains complex 'wiring' that reads a number from the memory and works out what instruction it means then does what the instruction says and then, often, moves to the next number and repeats this process forever (or until the power fails).
Some of these simplest instructions are actually add, subtract, multiply and divide. The CPU can perform these calculations at a typical rate of billions of times a second. It could be calculating where on the screen to draw something, deciding what to keep in memory and what to throw away, preparing to send information across the internet and many other things. Everything is done in tiny simple little steps but at a very high speed. The computer itself does not know what the purpose of the instructions are, it just blindly follows them, the sequence of numbers that tell the computer what to do is called a computer program. The operating system is just another computer program. Most computer programs are created by another computer program that reads the instructions written by the programmer (in a programming language of words and numbers that computer also only sees as numbers) and converts (process known as compiling) the programmers language into the numbers (instructions) that the computers CPU processes.
Nigel
2010-02-01 09:41:53 UTC
If you look at a simple document. Some simple maths is used for things like the size of the document. The document is made up of components ( paragraphs, tables etc. ) each has its own size. To find the overall size, simply add the size of the components together.
Even down to simple things - Unicode uses multibyte characters, so a string like 'Hello' would be 5 characters * 2 bytes per character = 10 bytes.
Sizes of images are similar - number of pixels wide X number of pixels high X bits per pixel / number of bits per byte ( This is simplified and doesn't take into account any image compression algorithm - which usually use more complicated maths to achieve compression ).
2010-01-31 20:12:11 UTC
math is always used in programming, because everything has an algorithm to it.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.