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

Just to add on to what others have mentioned (and lol students are the only ones forced to code in binary). The idea is that we can look at a set of bytes, interpret them in some standard way and perform actions.

To understand this a bit better, we can look at a very rudimentary computing model in which we have something called a bus (think of it as a series of parallel wires) which we fetch a set of bits from memory and pass them to another microchip. Don’t worry about how the bits get pushed onto the bus.

Now, let’s pretend this microchip has a magic way of doing different things based on the first 3 bits that were passed in (interested in this magic? You’ll want a multiplexer in a circuit). 000 might be encoded to do nothing. 001 might be encoded to take the remaining bits and store them somewhere, such as a another memory location, let’s say r1. 010 might do the exact same, but store it in r2. 011 might add the value of r1 and r2 and store the result in r1! 100 might print the value of r1 to the screen. 

So this is a toy version of how we get things done. Registers on a computer would be your r1 and r2. Interested in what these magic values are called? Look up op codes. They’re instructions that tell a computer how to fundamentally run and do things with data. (You can search for the x86_64 instruction set if you want specific op codes). 

The fundamental op codes tell computers how to manipulate bits. We can store, add, divide, write and read to memory based on bits now. Turns out you can get a lot done with that. (And many more operations!)

So all good, we can perform basic math and using our power of writing and reading to/from specific memory locations we can actually start to interpret our bits as other forms. 

At this point we have our compiler/linker take our text file and generate a bunch of bits that map to what we’re trying to do. So if I have something in my program called age:i32. Well I logically know it represents an age and can start treating it as an age. The compiler makes sure it gets treated as an integer with 32 bits and handles planning out the appropriate machine code.

So how about a basic string? Same thing!! It’s just a bunch of bits under the hood. Sure I could use an industry standard such as ascii or utf to interpret and interact with these bytes, but theres nothing stopping me from saying im going to write a program where 0000 0001 represents the letter ‘a’. At the language level we can logically group and hide lower level operations that make writing programs easier. 

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