Transcript from the "Binary Overview" Lesson
>> So I've mentioned binary like a million times already. And Bynary is so fascinating because at the core of it as Engineers, all we are doing is moving ones and zeros around. It doesn't matter what language you're writing. It doesn't matter how high level or low it's. At the end of the day, all we're doing is manipulating these tiny switches on a computer, on a CPU.
[00:00:26] And we're just turning them on and off a billion times a second. That's it. There's something beautiful in that simplicity. In that the things we build and these amazing contracts like browsers and games, and ebooks and websites. [LAUGH] And literally all the technology we use today, if it involves anything electronic, it's just a one or zero at the end of the day.
[00:00:57] And I love that. I don't know there's a beauty to that. I think the equivalent would be if I could speak and me speaking could create things. That's the same level that I think a programming at. Honestly, and this is my probably my first rant of the day I really think programming is magic.
[00:01:23] Okay, hear me out that seems a little strange, but we all use this fundamental force. We use binary to manipulate data to do things. So, we all understand that. It doesn't matter what type of language you're writing in. It's gonna compile down to binary ultimately and run on a computer.
[00:01:57] But at the end of the day, it doesn't matter. It's all about binary and how those instructions get written. I think that's so cool. To me there is no equivalence in the real world or anywhere in the real world. But there is no other analogy I can think of that as as powerful as the ability to have turn something on or off.
[00:02:19] And that dictates all these wonderful things we're gonna build. So, moving talking more about binary. Let's talk about the nomenclature behind binary. Binary, the smallest unit of computing we think of it's actually a one. I say ones and zeros, but a zero is just a state. So zero being off, one being on.
[00:02:42] That's it. So actually all we know about computing is a one, which I don't know. Take a minute. Yeah, that's kinda weird, right? There's only one thing we do and that's on or off. That's it. But the smallest unit and information in binary is a bit. So it's a 1 or 0.
[00:03:04] A group of eight bits is called a byte. And a byte is generally the smallest sequence of bits that we're gonna use, that we can get useful information out of. And I believe four bits is called a word. I haven't taken my CS. It's been a while since I had my CS degree.
[00:03:22] Somehow they gave it to me. I don't know how. But I'm trying to remember this nomenclature from back then, but we won't get into words. But once you understand what a byte is, we understand that a kilobyte is about 1000 bytes. Give or take, it's actually, 1024 because base two and all the other stuff.
[00:03:39] But, we will see bytes and bits later probably not that's as much but we'll see bytes. Because we will be directly manipulating these ones and zeros when we convert data into a byte array. A one and a zero is known as the base two system. So the bi, binary meaning two, it's just a counting system in computers.
[00:04:07] The system we're most familiar with is the base ten system, the decimal, deci meaning ten. And that just means that at any given position a number can be zero through nine. So there's ten positions I know I didn't say ten because ten is actually a construct of a nine and a one.
[00:04:28] I know it's a little bit different way about thinking of things. Binary being based two means there's only two possible numbers for any given position. That's a one or zero. And counting in base two, we start off with the first position. So we're looking at right here, we're looking at just the bite.
[00:04:46] So we're looking at eight bits of information. And we count base two and we increment by 24, 816, 32, 128, etc, etc, etc. That's why when you see memory written out, it's always in 64 kilobytes or 128 or 256. They're always some sort of power of two. That's how we count in binary.
[00:05:08] Don't worry, [LAUGH] I will not show you binary to ask you to figure out what it what it means. I had to do that in school. And I still am resentful for it because it doesn't really help you. [LAUGH] Like there's no way in programming that I'm going to be doing binary.
[00:05:24] Generally speaking, hopefully not. I'm not gonna be thinking in bits as much. I will be thinking in bytes, which are a little bit easier to reason about than just saying like, Is that 12345. Is that five zeros or not, okay, so five, that's 64 they flip that bit.
[00:05:43] Yeah, we're not really gonna do that we're always gonna deal in bytes, generally speaking, and it just makes reasoning about it much simpler. Are there any questions about reading binary and how the counting system works in base two and things like that? Because it's a little tricky to think 24816 doubling and that any position can only be pne or zero.
[00:06:08] And using that we base all of our numbers, everything we do strings, objects, numbers, doesn't matter. They're all based on this system at the core. Okay, I know. If you're saying this is so technical already, I'm sorry, I'm not really sorry. Yeah, you're gonna learn something. It's awesome.
[00:06:30] We're building up our this foundation of knowledge. You may know some of this. You may not be probably heard of it. But I guarantee you've heard of it. Okay, so it gets even more complicated. So we have, a byte of data. So that's eight bits, as we said before, but depending on the computer architecture, we might read bytes in ascending order.
[00:06:55] So that means the right most is the smallest number And the left most is the largest number at or we read it. So the left most is the largest number. And the right most is is the or the leftmost, the smallest number and the right most is the largest number.
[00:07:12] This format is known as Endian, which I always thought was a funny name. No one says computer engineers don't have a sense of humor because the naming is is interesting. But what we're gonna use today a web assembly and almost all, not almost all, but most of the modern computers use us Little Endian format.
[00:07:33] That is we read from right to left. There are some systems that still use big endian I can't think of any off the top of my head. But there have been some hilarious catastrophic bugs when people import code that is meant to be written in little endian. And it's in big endian and it just throws the whole system haywire because it's literally reading backwards.
[00:07:55] It's like trying to understand a book. By reading it backwards. Is it possible? Yeah, is it the best way to code? No, I, I only throw this tidbit of about Endian big endian because when you're reading documentation for webassembly and particularly assembly script enough, some of the other things we'll get to today, you will see that phrase Little Endian and Now you know what it means.
[00:08:17] It just means the order that we read the bytes in. Actually, that's a good time to jump. All right so, these are just jumped into the official Web Assembly documents make that a little bigger. I will say generally you're not gonna go here. [LAUGH] These docs, it's cool if you're maybe a systems engineer or a computer engineer who builds microarchitecture for web assembly.
[00:08:48] But I don't want you to be overwhelmed if someone's like yeah, just check out the documentation on web assembly. It's not really gonna be that useful to you in the context of this class, but it exists just so you know that I'm pointing you to the right resources.
[00:09:04] You can look up everything we're gonna talk about, and they'll explain it in a much more tactical manner generally speaking. But I wouldn't say you're gonna spend too much time on this site. But it's here if you need it.