+ 3

How computers know?

Hi everyone. When we type 2+2 in computers it execute =4 but how computer know that 2+2=4

21st Mar 2018, 2:33 AM
Maninder $ingh
Maninder $ingh - avatar
2 Answers
+ 3
Computers turn every number into binary. The numbers that we use are expressed in base 10. Every 10 1s equals 1 ten, every 10 tens equals 1 hundred, and so on. In binary, you go up a unit every 2 numbers. So 2 ones equals 1 two, 2 twos equal 1 4, and so on. For example, the number 9 would be 1001 in binary: 1 one, 0 twos, 0 fours, and 1 eight. 1 + 8 =9. Computers do this because it is easier to design circuits that only have values of 1 or 0 than circuits with 10 separate values each. Addition Computers have basic mathematical operations like addition and subtraction programmed into them. Adding in binary is extremely simple. If you have 2 numbers with a 1 value, you store a 0 and move carry 1. Otherwise, you record the bigger of the two numbers in that slot. For example, if you are adding 5 + 4, you get: 0101 + 0100. In the first slot, you have a 1 + 0, so you store the bigger number, 1. In the second slot, you have two 0s, so you store 0 (since both numbers are the same. In the third slot you have two 1s, so you store a 0 and carry a 1. You end up with the number 1001, or 9. Multiplication. Computers use long multiplication, but they do it in binary. If the computer multiplies a number by 1, it returns a 1. This is a much simpler system than base 10, even though it does require more steps. For example, in base 10 the problem 8 * 9 is an easy, 1-step problem with no long multiplication. However, in binary each number is 4 digits long, and the solution is 7 digits long! Subtraction Subtraction is done in two steps. Rather than subtracting a number, a binary computer adds its compliment, a number with ones where the original has zeros, and zeros where the original has ones. For example, whereas 4 is 0100 in binary, negative 4 is 1011. So, for 7 - 4, we get 0111 + 1011 = 10010. The number at the leftmost side is then moved to the right, giving us 0011 = 3. source: sciencing.com
21st Mar 2018, 2:46 AM
Nilesh
Nilesh - avatar
+ 2
Considering you are running this mathematical problem on a computer with an operating system, then the simple answer is because the OS is equipped with tools that are familiar with mathematical input. The long answer is that computers are entirely based on mathematics. Programming languages and the compilers/interpreters that they are equipped with are familiar with the functionalities of the specific language they are for, and programming languages are math derived. They were made to understand mathematical equations, and equation-like writing.
21st Mar 2018, 2:43 AM
Dread
Dread - avatar