Web Assembly (Wasm)

Binary Overview

Jem Young

Jem Young

Web Assembly (Wasm)

Check out a free preview of the full Web Assembly (Wasm) course

The "Binary Overview" Lesson is part of the full, Web Assembly (Wasm) course featured in this preview video. Here's what you'd learn in this lesson:

Jem introduces the "bit" which is the smallest unit of information in computing. A group of eight bits is called a byte. Some computer architectures read bytes from right to left, or little endian. Others read bytes from left to right, or big endian.


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.

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.

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.

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.

But kind of like Hogwarts and Harry Potter, there are different schools of thought about how we should use this binary language to get our our means. And people are firmly entrenched and JavaScript is better and C is better or I wanna use Rusts or Elm or whatever language you want to use.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now