eli5 How do people code with binary?

1.27K 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

The vast majority of programming does almost nothing with binary. The programming language lets you use defined syntax to do all of the operations you need to do. Then there is the compiler which converts the normal, mostly easy to read syntax into machine code, which even there, will mostly use a hexadecimal representation (base 16) of the data. They use hexadecimal because it is base 16, which means 4 binary digits can fit in one hexadecimal digit. So a byte, which is 8 binary bits, can be two hexadecimal digits. So for example the binary 10110100 could be written as can just break that into 1011 and 0100 which is B4 in hexadecimal.

As for how to get strings (ie letters and symbols) out of pure 1s and 0s, the standard for that is either ASCII or for richer character possibilities, UTF-8 or UTF8.

ASCII uses a single byte (8 bits or 8 1s or 0s) and has a symbol table to say for example 109 in base 10, or 6D in hexadecimal, or 01101101 in binary means the letter “m”. With that, as long as your code knows you are looking for a string, then the machine code can grab however many bytes it needs to complete the string.

For UTF8, instead of each character being one byte, each character can be 1-4 bytes. This means that UTF8 is a little more confusing at the first byte needs to tell the machine code how many bytes there are in this character, as well as containing the actual character if it is just a single byte. With this though, a single UTF8 character could represent over 1 million different things. This means characters in every other written script can still be encoded with a single UTF8 character. So for example, the hex value 5a23 is the UTF8 representation of 娣 in Chinese.

The main takeaway though, is that unless you are writing a compiler, or writing embedded c code, you will basically never need to know that there is 1s and 0s representing everything under the covers, as the compiler takes care of that for you.

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