DEV Community

Play Button Pause Button
Vaidehi Joshi for The DEV Team

Posted on

BaseCS: Intro to Binary

Welcome to BaseCS Season 2!

Today's episode of BaseCS focuses on the core concept of what makes computers work: binary!

Binary is a number system where the digits that we can use are either 0 or 1. In this episode, we learn about why we're limited to just these two numbers, and how they're related to the on/off switches inside of our machines. We also learn how these binary is used to measure memory and data, and what a bit and a byte are.

Learn more about the concepts covered in this post here:

This whole series is sponsored by Heroku. A special thank you to Heroku for their ongoing support!

Top comments (14)

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

Fan screaming at the return of a favorite series.

Ahem.

Excellent explanation as always, Vaidehi. Just one technical note to add:

Some standards board dweebs redefined KB/MB/GB/TB to be strictly decimal; that is 1 TB = 1,000 GB = 1,000,000 MB = 1,000,000,000 KB = 1,000,000,000,000 The claim is that it's "easier" for users to understand this. The suspected reality is that it lets hard drive manufacturers effectively shortchange consumers. "2 TB hard drive! (except it's actually only 1.8, wink wink)".

Because of this, they've also defined the units KiB ("kibibytes"), MiB ("mibibytes"), GiB, TiB, and so on. Those still follow the normal rule of 1024.

Collapse
 
spqrbob profile image
Bob McCann • Edited

What a crock! The B in those abbreviations KB/MB/GB/TB stands for byte! As everyone who has worked with computing at this level knows, a byte is 8 bits long, and is capable of holding 256 different values. These values increase/decrease in powers of two, which represents the addition or subtraction of a bit to the existing bit count (check my math and call me on my errors):

<# of Bits> = <# of Values That Can Be Expressed>

4 bits = 16 (1 nibble [nybble], 0x, 1 unit of hexadecimal)
8 bits = 256 (1 byte, B, 1 character in ASCII)
10 bits = 1,024 (1 kilobit, KiB, 1 character in UTF-8 [1-4 bytes])
13 bits = 8,192 (1 kilobyte, KB)
20 bits = 1,048,576 (1 megabit, MiB)
23 bits = 8,388,608 (1 megabyte, MB)
30 bits = 1,073,741,824 (1 gigabit, GiB)
33 bits = 8,589,934,592 (1 gigabyte, GB)

And so on for terabyte (TB) and up the ladder we go....

To deny the powers of two in favor of the powers of ten should be an affront to everyone who deems themselves a computer scientist! The hard drive, thumb drive, SD/Micro SD card, etc. manufacturers have been printing the weasel words of the "powers of ten" valuation for their so-called top of the line products for years now. There is no need for some chucklehead sitting on some committee (that they should be immediately and unceremoniously ejected from) to actually enshine such tomfoolery as being some kind of actual standard. Please tell me exactly which standards board has gone public with such a "pickled hard-boiled egg fart" of a ruling so that I might write them a strongly-worded letter for which task I am singularly equipped!

I don't know when I became a grouchy old curmudgeon shaking my fist at those who would show such disdain for the fundamental truths that lie at the very foundations of our entire field of knowledge, yet here we are.

Bunch of young whippersnappers! Get offa my lawn!

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

Indeed.

Waves his cane in disgust.

Kids these days.

Collapse
 
aaronmeza profile image
Aaron Meza • Edited

And kilo has a long-standing definition in science - it's the SI prefix that means to multiple by 1000. Yes, when you're working on the bit level it makes sense to think in powers of 2 (and I've done this, working on tar streams and file system drivers and whatnot where things sometimes don't align on byte boundaries).

As you said, the B means byte which is 8 bits. That still doesn't change the fact that kilo means 1000. Kibi means 1024. Kilobyte = 1000 bytes. Kibibyte = 1024 bytes. This isn't a new-fangled definition.

Thread Thread
 
codemouse92 profile image
Jason C. McDonald • Edited

While "Kilo-" does indeed mean 1000 in and of itself, "Kilobyte" has always meant 1024 until recently. Retroactive continuity amendments aside, since KB started out as meaning 1024, it should have persisted on meaning that.

Collapse
 
thomasbnt profile image
Thomas Bnt

Hello ! Thank you for this reminder that !

Can you post the reminder sheets you make? It reminds me of the reminder sheets I used to make for myself in class once upon a time. Plus you use bright colors!

Collapse
 
ryansmith profile image
Ryan Smith

Great video! I am looking forward to the rest of the season.

It is useful to have some working knowledge of binary, even for self-taught or bootcamp attendees/grads, so I recommend checking out all of baseCS' content. Every time data is added to a program, it stores binary data to the computer's finite memory or finite storage which can cause inefficiencies in your program if you aren't careful. If a value is not needed or used, get rid of it! Also, every line of code is eventually translated to binary instruction(s) to execute on a CPU, which can only run one instruction at a time. Remove that unnecessary code!

How can I get that cute giraffe on Ben's desk? 🦒

Collapse
 
devanghingu profile image
Devang Hingu

Nice information for newbie who started career in CS. Your bits, bytes examples are really makes sense. i like it.

Collapse
 
chengxi profile image
chengxi

Hello.
nice to meet you
I hope that we get in touch each other in the future.
thank you.

Collapse
 
vaibhavkhulbe profile image
Vaibhav Khulbe

BaseCS is here! Time to go back to my school days 🥺

Collapse
 
lauragift21 profile image
Gift Egwuenu

Awesome! Looking forward to following this series.

Collapse
 
jenc profile image
Jen Chan

TIL that circuits run on binary! Wowowowwww!!!

Collapse
 
jesstivey profile image
jesstivey

Thanks for the great episode!

Collapse
 
jess profile image
Jess Lee

What a great episode to kick off season two!