DCS #3 - How can you do anything with 0s and 1s?

in #science7 years ago (edited)

DCS-03.jpg

Hello everyone.

In this Decomplicating Computer Stuff post I am going to answer a question that I personally had a few years ago: if computers can only understand 0s and 1s, how can they do anything? How can they execute complex calculations, display images, play sounds and all sorts of things with just these two simple numbers?

This is often represented in movies and television where characters look at screens with some rather cryptic computer code.

bender.jpg
Bender from futurama looking at binary code (Source)

The first thing you have to understand is that our everyday decimal numbers can all be written with 0s and 1s, this is what we call binary representation. How does it work? Check this out:

binary-rep.jpg
A binary representation of the number 42 (Source)

In binary, each digit represents a power of two and the 0 or 1 will tell if that power is present or not so the first digit (read from right to left) will represent 20, the second is 21, the third is 22 and so on. This way, the final value is defined by the sum of all powers that are present in the number so something like 101 = 1x20+0x21+1x22 = 5.

Even negative and real numbers can be represented. A computer can be manufactured to know that binary number representations will be split into a bit for sign (1 for negative, 0 for positive for instance), a few bits for mantissa and a few bits for exponent so -14,52 could be separated into -(sign) 1452(mantissa) 10-2(exponent) and each part represented in binary.

float.jpg
Figure shows one way a computer could see a Real number (Source)

The number of binary digits in each number vary from computer system to computer system. This is why you may often hear about 8, 16, 32 or 64 bit systems. It's simply saying how many digits the computer is using to represent numbers. The more digits you have, the bigger the numbers you can represent (and also the memory size you need to store them).

We use those binary representations because they are much easier from an electronic standpoint. You could say something like 5V tension will be a 1 and 0V will be a 0, this is much simpler to store and manipulate in circuits than decimal numbers with 10 different symbols, believe me.

So what? Its just numbers. What about all the rest?

The two basic things you need to have in a computer are memory and processor. Memory is simply a big list of spaces where you can store values. And each space can be found by its address which is also a binary value!

memory.jpg
Simplified representation of a memory (Source: myself)

Processors on the other hand are used to execute operations. They have lots of different commands implemented in hardware and each command has a code which is the identification number of that operation. This way you can have addition=0000, subtract=0001, store=0010, read=0011 and so on.

When the computer runs a program that is in memory it will consider the values as operations and parameters for the commands so it could, for instance, execute a command that adds numbers X and Y and store result on address Z. There are also commands for comparing numbers, and jumping to different memory address depending on the result so you can implement if-else statements (ex: if a >b do this or else do that).

Intel-processor.jpg
Example of a processor (Source)

Congratulations, you have just looked into the bare bones of almost every computer out there! There is, of course, much more to cover but now you know the basics of how computers use binary numbers to do stuff. See you in the next posts.

Til next time,

Anderson

Coin Marketplace

STEEM 0.26
TRX 0.20
JST 0.038
BTC 96757.59
ETH 3590.54
USDT 1.00
SBD 3.76