eli5 How do people code with binary?

1.28K viewsOtherTechnology

Like I get that it can be a 1 or a 0, and that stores information, but how do you get information out of that? And how do people code with it? Seems like all it could store is numbers

Edit: Thank you all, this is very helpful

In: Technology

26 Answers

Anonymous 0 Comments

People do not in general code in binary, it is extremely hard for humans to read.

The CPU is built so it interprets binary data as instruction in a specific way and will start to do that at a specific memory adress when powered on. It is a table where for example if the finest 8 bits are 0000 0001 it should move data from locations specified in the following bits. It not that different to if you read “turn on the oven” it is not text but induction to do a specific tasks, because you know the meaning of those letters

You could write an induction as 01001000 10001001 11100101 if you like. This is a machine, what the CPU understand. Every induction to the CPU is like this. It is build to interpret what it should do from it.

An alternative is written in hexadecimal where 4 bits are on digits from 0 to 15. 10 to 15 use A to F as digits.

In hexadecimal the same thing is 48 89 e5

That is still hard for humans to read, there are a human-readable form called assembly and it in the induction is

mov rbp, rsp

rbp and rsp are registers and the insoction moves (copies) the content in rsp into rbp. There is a 1 to 1 mapping between assembly and machine code in hex or decimal.

You could look it all up in a table but is is simpler to let a computer program do that and output it in a more human-readable form.

Assembly code to make it easier to read from humans first appeared in 1947, the first assemblers that covert it automatically is from early 1950. So even when the number of computers in the works likely could be counted on your fingers people found a way to get away from programing in binary,

Assembly is sometimes used but most of the time higher-level languages are use that convert it to machine code. This is done by a compiler.

An example is a simple hello world in C that looks like

#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf(“Hello, World!”);
return 0;
}

It can be compiled to the following assembly code

 push   QWORD PTR [rip+0x2fca]        # 403ff0 <_GLOBAL_OFFSET_TABLE_+0x8>
 jmp    QWORD PTR [rip+0x2fcc]        # 403ff8 <_GLOBAL_OFFSET_TABLE_+0x10>
 nop    DWORD PTR [rax+0x0]
main:
 push   rbp
 mov    rbp,rsp
 mov    edi,0x402004
 mov    eax,0x0
 call   401030 <printf@plt>
 mov    eax,0x0
 pop    rbp
 ret

If you compile the C code yourself at [https://godbolt.org/](https://godbolt.org/) you can see the machine code in Hexadecimal too.

You are viewing 1 out of 26 answers, click here to view all answers.