Beginner's Guide to Coding and Data

Level: Beginner

Convert decimal to binary using Javascript | Text to binary with code

video

expand_more chevron_left

text

expand_more chevron_left

Unveiling Text to Binary Conversion

Welcome everyone! In this lesson, we'll dive deeper into the world of text to binary conversion, understanding how JavaScript makes this magic possible. So, without further ado, let's get started.

Prerequisites

To fully grasp this lesson, it helps to have a foundational understanding of character encoding and positional numeral systems. Topics we'll cover include:

  • Character codes
  • Unicode mapping
  • Converting to binary

As a reminder, character encoding is a system for representing characters in a digital format. In today's digital age, Unicode is often the go-to encoding method.

JavaScript Code Behind the Scene

With the background set, let's delve into the JavaScript code that turns text into binary. We'll explore two significant pieces of JavaScript code:

  • charCodeAt()
  • toString()

The charCodeAt() function helps us to obtain the Unicode character code, while toString() aids in the conversion from decimal to another base, such as binary.

// Converting the first character 'D' to Unicode
let unicodeValue = "D".charCodeAt(0);

// Converting the Unicode value to binary
let binaryValue = unicodeValue.toString(2);

Troubleshooting & Best Practices

During the coding process, we may run into some common issues. For instance, we can't simply type a number or character without specifying its type.

To let JavaScript know that we are working with a string, we use quotes. Similarly, for numbers, we can use the Number() function to specify the type.

// Correct way to specify a string
let char = "D";

// Correct way to specify a number
let num = Number(100);

If you're new to coding and find some of these examples intimidating, don't fret! Keep working and you'll get it!

quiz

expand_more chevron_left
deeplizard logo DEEPLIZARD Message notifications

Quiz Results

resources

expand_more chevron_left
In the text-to-binary video, we saw how to go from text, to character codes, to binary numerals. In this video, we are going to see how this works behind the scenes using JavaScript. Understanding how we can go from text to binary is pretty straight forward after we understand how character encoding and positional numeral systems work. Let's see how to do this in code. Discussion of String.charCodeAt is here - https://youtu.be/M8CbBfx5228?t=91 Prerequisites videos: Numerical data explained - https://youtu.be/YDDqe60omL0 Textual data explained - https://youtu.be/-XLZadCdo9Q *Unicode explained - https://youtu.be/M8CbBfx5228 Numeral vs Number - https://youtu.be/RSdnNZBj8HQ **Binary vs Decimal - https://youtu.be/-MM6PcEQnWc Hexadecimal explained - https://youtu.be/JlLnt4aJEK0 5 Patterns with Numbers - https://youtu.be/-iMpJ-xGG4k * Character encoding ** Positional numeral systems Related video: Is your name also a number? - https://youtu.be/jxYi4RGlIV4 Notebook - https://beta.observablehq.com/@deeplizard/text-to-binary-and-back πŸ•’πŸ¦Ž VIDEO SECTIONS πŸ¦ŽπŸ•’ 00:00 Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources 00:30 Help deeplizard add video timestamps - See example in the description 03:17 Collective Intelligence and the DEEPLIZARD HIVEMIND πŸ’₯🦎 DEEPLIZARD COMMUNITY RESOURCES 🦎πŸ’₯ πŸ‘‹ Hey, we're Chris and Mandy, the creators of deeplizard! πŸ‘€ CHECK OUT OUR VLOG: πŸ”— https://youtube.com/deeplizardvlog πŸ’ͺ CHECK OUT OUR FITNESS CHANNEL: πŸ”— https://www.youtube.com/channel/UCdCxHNCexDrAx78VfAuyKiA 🧠 Use code DEEPLIZARD at checkout to receive 15% off your first Neurohacker order: πŸ”— https://neurohacker.com/shop?rfsn=6488344.d171c6 ❀️🦎 Special thanks to the following polymaths of the deeplizard hivemind: Mano Prime πŸ‘€ Follow deeplizard: Our vlog: https://youtube.com/deeplizardvlog Fitness: https://www.youtube.com/channel/UCdCxHNCexDrAx78VfAuyKiA Facebook: https://facebook.com/deeplizard Instagram: https://instagram.com/deeplizard Twitter: https://twitter.com/deeplizard Patreon: https://patreon.com/deeplizard YouTube: https://youtube.com/deeplizard πŸŽ“ Deep Learning with deeplizard: AI Art for Beginners - https://deeplizard.com/course/sdcpailzrd Deep Learning Dictionary - https://deeplizard.com/course/ddcpailzrd Deep Learning Fundamentals - https://deeplizard.com/course/dlcpailzrd Learn TensorFlow - https://deeplizard.com/course/tfcpailzrd Learn PyTorch - https://deeplizard.com/course/ptcpailzrd Natural Language Processing - https://deeplizard.com/course/txtcpailzrd Reinforcement Learning - https://deeplizard.com/course/rlcpailzrd Generative Adversarial Networks - https://deeplizard.com/course/gacpailzrd Stable Diffusion Masterclass - https://deeplizard.com/course/dicpailzrd πŸŽ“ Other Courses: DL Fundamentals Classic - https://deeplizard.com/learn/video/gZmobeGL0Yg Deep Learning Deployment - https://deeplizard.com/learn/video/SI1hVGvbbZ4 Data Science - https://deeplizard.com/learn/video/d11chG7Z-xk Trading - https://deeplizard.com/learn/video/ZpfCK_uHL9Y πŸ›’ Check out products deeplizard recommends on Amazon: πŸ”— https://amazon.com/shop/deeplizard πŸ“• Get a FREE 30-day Audible trial and 2 FREE audio books using deeplizard's link: πŸ”— https://amzn.to/2yoqWRn 🎡 deeplizard uses music by Kevin MacLeod πŸ”— https://youtube.com/channel/UCSZXFhRIx6b0dFX3xS8L1yQ ❀️ Please use the knowledge gained from deeplizard content for good, not evil.

updates

expand_more chevron_left
deeplizard logo DEEPLIZARD Message notifications

Update history for this page

Did you know you that deeplizard content is regularly updated and maintained?

  • Updated
  • Maintained

Spot something that needs to be updated? Don't hesitate to let us know. We'll fix it!


All relevant updates for the content on this page are listed below.