Web Assembly (Wasm) Convert Hex & Binary with toString
Transcript from the "Convert Hex & Binary with toString" Lesson
>> We understand how to read Hex. We can convert it easily. I know, I'm sorry, I tricked you. I made you go through the exercise where you're probably writing it down by hand. We can do this using programming because we're programmers, that's what we do. We're lazy. We don't wanna have to memorize how to convert things.
[00:00:59] Or we'll go through the first one. So if we want to run a function that converts hex to decimal. And decimal being our modern number system that we all know and love, we can just create a function called hexadecimal. It's gonna take a hex in, and then we're gonna pass it to the toString method with a base 10.
[00:01:17] And actually, let's fire that up. Let's see if if I'm lying or not. You never know. I'm just gonna copy it, cuz, lazy, I think I've mentioned that before. And what was the number we just did text to decimal? What are we trying to convert it was,
[00:02:11] It's a common mistake I make. So we see that converts to a 759. I don't think it's 2x7, was it?
>> I must have said the wrong number.
>> Trying to make me look bad.
>> [INAUDIBLE] [LAUGH]
>> [LAUGH] I was like, did I get my math wrong, which happens a lot.
[00:02:28] 743, so that's easy. Now in the future you can write your own utility methods if you really wanna nerd out, which I encourage you to do at maximum nerd volume. You can write your own methods convert to and from different formats. So, without cheating, write a function that converts decimal into binary.
[00:02:49] And to me this is really gets really interesting cuz you actually see what numbers represent in 0s and 1s. And I should mention for the exercises, yeah, you can copy paste code, but in all of my years of learning, I have discovered that I learn and I think most people learn when they actually write it down.
[00:03:10] There's something about the muscle brain connection, I forget what it's called in actually like kinesiology. But there's something about your muscles doing something, your fingers doing something, and your brain comprehending that, that makes it stick more than if you just copy and pasted like yeah, that was pretty simple, I did it.
[00:03:32] But I really encourage you to actually do the exercises and not just copy paste them or look at them. I promise it's seems like the hard way, but you will learn a lot better when you code it yourself. Yeah, it's the same principle as before, we're just passing a different radix to the toString method.