Talking to a computer
[ << ]
Later on in coding, it is sometimes useful to know that computers don't really speak these languages.
Computers are made of millions of switches controlled by, and controlling the flow of, electricity.
The switches can be on or off. When we "run" a program (set it working), it sets the switches to do different jobs by controlling the
flow of the electricity.
For example, in our "Hello World" program, what we think of as an "H
" might be a row of switches
our program sets to:
on off off on off off off
We write this with "1
" for "on
"
and "0
" for "off
" like this:
1001000
You can play with an example here.
Some groups of ones and zeros mean things other than letters. So:
1100110110000000
might mean "end this program". Another group will mean "turn on the switches lighting up bits of the screen".
You can write programs in 1
s and 0
s
("binary coding") but this is very hard.
Here is "Hello World" in binary.
Can you find the ones and zeros for the "H" of "Hello World"?
To help it will light up when you put the mouse over it.
0 1 1 1 1 1 1 1 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0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 0 0 0 1 1 0 0 1 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 1 1 0 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 1 1 0 0 0 1 1 0 0 1 0 0
It isn't easy even to find "H". Think how hard it would be to type all this and spot any wrong bits. It doesn't even make sense: the code for "end this program" comes before the "H", because that's how the computer likes it. Coding like this would be crazy, but sometimes it is useful to know the computer works with this stuff. The main job programming languages do is to make coding easier than writing binary.
So, if our computer needs ones and zeros, how do programming languages work?