# How important is learning Binary for first-year college students?

I teach my freshmen Binary because I'm old school I guess. I do want them to know how data is stored and that means Binary to me. How do others feel? Is it a must learn early or a nice to have if there is room?

• Can you specify your audience? Is this 1st year high school or university? Is the course for Computer Science majors, or everyone? Jun 22 '17 at 19:26
• There is a big difference between teaching it, mentioning it in passing or using it as an example when teaching hex. You could just as usefully teach hex as having a 4 bit mapping for each digit, and that would be closer to what designers use most of the time. Jun 22 '17 at 23:23
• If you don't understand binary you're going to have a hard time with bitmapped flags--and high level languages do have bitmapped flags. Jun 23 '17 at 4:26
• Wait, you mean they haven't been taught number representations in high school? I'm truly shocked. Jun 23 '17 at 6:50
• @LorenPechtel your comment made me realize I haven't manually built a binary bitmapped flag in years (actually, since my 2nd college year). Nowadays, most popular functions use constants that you can OR together, e.g. PHP's json_encode. We are so spoiled! Jun 23 '17 at 9:51

Binary is fundamental to programming, but this has a lot more to do with logic than just with data storage.

Computers work on "yes greater than no" or "no greater than yes." There are only two choices.

Boolean logic has only two truth values, "true" or "false." Boolean logic is fundamental to computers.

In more advanced CS subjects such as information theory or security, you have such a concept as "bits of entropy." On a theoretical conceptual level this has nothing to do with data storage or even number systems and has everything to do with actual binary mathematics.

If you do anything with hardware, boolean logic and binary become essentially intertwined and totally indispensable.

Further, if you are typing on a computer or doing anything with text, ever, ever, on computers, you are dealing with character sets. As a programmer there are certain things that you MUST KNOW about character sets. :) Understanding those things requires a grasp of using bits and bytes to store data, and how much information can be stored in them (256 distinct bytes), which goes back to information theory. And also finally comes to data storage.

You can abstract away the hard stuff sometimes, but you're teaching Computer Scientists. Not part-time kiddie hackers who don't know or care how the magic happens. Do you want them using Shlemiel the painter's algorithm due to their ignorance?

Besides, all abstractions are leaky. And binary isn't even an implementation detail. It's totally fundamental to understanding computers at any level.

I can't imagine teaching Boolean logic without teaching binary, or teaching binary without teaching Boolean logic. As for the actual binary place value system, it's really not that hard. I've taught this stuff successfully to seven year olds.

Hex and octal are less mandatory but provide useful comparison and contrast to help understand the binary place value system itself.

tl;dr: Binary is a must learn early in CS and any related subject.

Don't be like the handwriting teacher teaching "traveling ovals" for months and months when his students can't even write their own names.

Let's have some professional computer scientists who know their basics rock solid, please. :)

• I feel like the tone here says students will be completely lost without understanding binary, which is hyperbole. It's a pretty easy thing to learn at any point. But I do agree that it's much easier to understand later CS concepts with a good grasp on binary. I recall several projects in C that would have been much easier if I understood bits and bitwise operators and how to use them. Jun 23 '17 at 13:14
• @ChrisSchneider I'm trying to think of a single CS concept that isn't rooted in or directly related to discrete elements, Boolean logic or binary. What would you teach of CS to students who didn't know these things? I'm really wondering. Jun 23 '17 at 13:24
• Boolean can be understood quite easily without understanding binary or even knowing it exists. True and false are real world concepts not exclusive to CS and kids learn about > < == in 2nd or 3rd grade. I mean, that is still binary, just not taught as a CS concept. Jun 23 '17 at 13:36
• how do you know OP is teaching computer scientists? It could just be an introductory programming course, in which case I would not expect binary to be taught. It's absolutely not required. Jun 23 '17 at 16:47
• You didn't stress this enough: Learning binary is the most important thing a first-year can learn! Living in a mostly decimal world working with binary numbers is the best way to learn about models, transformation and data representation as such. Even though it's never explicitly communicated this way. Jun 24 '17 at 20:28

I see no reason to teach binary in an introductory programming class. It is not generally needed (see exceptions below) when programming in high-level languages, which is usually what is taught to freshmen students. If you have extra time in your course, rather than introducing binary, why not introduce them to other areas of CS that freshmen don't usually see, such as human-computer interaction, algorithms, computing history, Moore's Law, assistive technology, internationalization, etc.

I teach binary when there's a need to: in Computer Architecture, which is a required (2nd- or 3rd-year) course in our undergraduate CS minor and major. It is absolutely necessary in that class, to understand how processors work, how caches work, and how numbers and Unicode characters are represented. I don't teach Computer Networks but could imagine its being taught there.

If a curriculum does not include Computer Architecture, students should still learn enough about binary numbers and floating point encoding so they know why floating-point arithmetic is inexact.

If/when you do teach binary, teach them how to count on their fingers in binary.

I give extra credit in Computer Architecture for counting up to 31 on one hand. Just be careful...

• I always make that joke about 132. :)
– Ben I.
Jun 22 '17 at 21:58
• I'm very careful about that in the HS classroom. Jun 23 '17 at 16:51
• Good point, @AlfredThompson. I teach at a women's college, where the students are more mature than high schoolers. Jun 23 '17 at 17:54
• @ChrisStratton Whether programmers should know binary is a different question than whether they should learn it freshman year. Big-O notation is important, but students typically don't learn that until their second year of college CS. Jun 24 '17 at 0:57
• Big-O notation is far less important. First, the notation itself does nothing; it's the concepts it expresses - you can have perfectly fine conversations about efficient computation without involving it at all. But even then, ignorance of algorithmic efficiency may get you slow code; but ignorance of numeric formats yields broken code. Jun 24 '17 at 1:03

I introduce binary on Day 1 (if not Day 0). However, in my class, learning binary is not an end in and of itself: it is a means for understanding the fundamental concept of abstraction.

As a teacher of AP CS Principles, I follow the College Board standards for the course. In that sense I have to teach binary, decimal, and hexadecimal, and conversions between and among them. The first "Enduring Understanding" under "Big Idea 2 - Abstraction" focuses on digital representation of data:

Students will understand that...

EU 2.1 A variety of abstractions built on binary sequences can be used to represent all digital data.

Having taught them binary, we can discuss storage limitations of different data types, floating-point imprecision (as Ellen mentioned), use cases for different bases such as octal and hexadecimal, and file signatures, among many other topics. We use xxd to investigate a bitmap (and dive deeper into color representation) and to examine the metadata stored in pictures taken on a cell phone.

Do I think binary-for-binary's sake is worth it? Probably not. It's a lot of work for not a huge pay-off for a beginner programmer, and it's easy enough to look up a binary-decimal converter.

Is it worth it to understand binary in terms of the larger context of abstraction and to be comfortable occasionally looking at and deciphering representations of it (along with octal or hex)? Absolutely. It's how all digital data is represented, and the groundwork should be there in some form from the start.

Student: My program is adding a list of positive ints in a loop, but the total ends up negative! What happened?

Teacher: int can only store numbers up to Integer.MAX_VALUE, after which it wraps around to negative values.

Student: Huh? Why do we call it int then? That's not how integers work!

Teacher: Uh, well, it's an abstraction, but some abstractions aren't perfect.

Student: [looks up Integer.MAX_VALUE...] Why is the maximum value 2147483647? That's a pretty arbitrary number.

Teacher: Computers represent integers in binary... [mini-lecture follows]

Student: Okay, fine. But Integer.MIN_VALUE is -2147483648; why isn't it symmetric? What happens if we negate Integer.MIN_VALUE, then?

Teacher: [two's complement mini-lecture]

You may or may not want to teach a specific lesson on binary (and octal and hex, and depending on your students, the concept of place value in general), but your students are going to run into leaky abstractions at some point, and you should be prepared to provide just-in-time education.

If you're working in a language with arbitrary-precision integers, you get to delay this line of questioning until your students wonder why addition suddenly gets slower once the values get large enough. General understanding of how values are physically represented will also help students with questions like "My program runs great on my desktop, but when I tried to run it on a Raspberry Pi, it runs out of memory. How can I make it use less memory?"

• Hi Jeffery! Welcome to Computer Science Educators! This is a good answer, and we hope to hear more from you in the future. I like your use of an example conversation. Jun 23 '17 at 20:42

When teaching first year CS students, I very briefly touch on Binary -- basically just explaining that 1 means on, 0 means off, and what it means to have a number of base X (i.e. I go over why Decimal numbers work the way they do in relation to Binary).

I think this depends greatly on the curriculum at your institution, but I have never found students to struggle later in their education due to someone skimping on Binary their first year -- as such, I err on the side of letting them explore it deeper in subsequent classes.

• Nice answer. Welcome to CSE!
– Ben I.
Jun 22 '17 at 20:33
• @BenI. Thanks! Please feel free to let me know if my answer could be improved. Jun 22 '17 at 20:36
• Re, "1 means on, 0 means off." If you're using bits as BInary digiTS, then 1 means 1x2^n where n is the bit position, and 0 means 0. If you're using them for any other purpose in software, then 1 and 0 mean whatever the developer wants them to mean. If you're using them to control hardware, then 1 and 0 mean whatever was convenient for the hardware designer. (Back in the days of TTL logic, 0 often meant "on" and 1 "off".) Jun 23 '17 at 3:31
• Ah, sorry, my answer isn't completely clear there. I'll figure out how best to update that. Thanks! Jun 23 '17 at 13:52

In my experience, kids need a second exposure to binary before it starts to really sink in. During sophomore and junior years, we use binary heavily for certain key moments at my school, so that freshman exposure is absolutely vital. I still have to present it a second time when they are sophomores, but I can only imagine how much harder all of that material would be without the benefit of covering it the first time.

• Our first real Computer Science Problem: How do you change base representations of numbers. Here is a big fat place to introduce mod (%). Jun 22 '17 at 22:49

Binary is ESSENTIAL for designing digital logic, so be sure to include it for students who plan to become electronic engineers working in digital design.

• Strongly disagree. Digital logic is designed at a higher level of abstraction than this. Yes, eventually the mapping to bits is relevant, but datapath is mostly '+' and '-' functions. Logic, yes. Binary not so much. Jun 22 '17 at 23:16
• @SeanHoulihane - boolean logic is literally about binary states. Jun 23 '17 at 8:44
• @Davor yes, as in 2 state logic (or sometimes 4). Nothing to do with power of 2 number systems. Jun 23 '17 at 9:03

In an Introductory class I would hope to see it at least mentioned. As they get deeper into a CS curriculum then they should become more adept at moving between Binary, Hex and Decimal (as well as Ascii, UTF-8, etc.) so that they have an understanding of how the computer they code for consumes their code.

You'll need to structure it so you don't get too derailed. Binary can be a course unto itself as you shift into math, even Big vs Little endian can cause headaches early on.

You also mentioned "storage". Both Text and "binary files" (think EXE, SO, DLLs etc.) have OS variations that you could look at. Perhaps you meant over the wire; so more XML, JSON, and/or HTTP - all interesting aspects.

I'd advise keeping it on topic, focused, and clearly understandable by your audience.

Understanding binary, hex, and octal numbers contributes to insight on the workings of computers, although octal numbers are fading in importance in comparison to hex numbers. Here are a few reasons

File permissions are managed with octal digits. The command

chmod 644 file.txt

uses three octal digits to set the visibility of the file. (4 read, 2 write, 1 execute so the 6 means read/write for the user and the 4s mean read permission for the group and others)

Colors are represented by hex codes; a color and its transparency are represented in a 32 bit integer (8 bits for red, green, blue, and alpha [transparency].

Memory addresses are output as hex code. It is indispensable for every beginning programmer to be aware of the meaning of memory addresses. Note that Python and Java variables are basically..... pointers.

Hex and octal numbers are conveniences for humans because they shorten a number's representation. Everything stored in the computer and the file system consists of one-dimensional streams of bits.

I feel it is important to know binary. Some students find it enjoyable (and some might even use it in their projects to encode and decode custom data) and those who don't simply ignore it.

I think it's good to teach it because a) it gives students the notion of how computers actually work (they know it works with electricity, so 0 is low current, 1 is high current) and b) it's useful in coding, as they can use it to serialize data.

Eventually, if there's time, teaching how it can be used is good, and not only what it is.

• Changing base representations of numbers is an excellent early example of a non-trivial algorithm. Jun 26 '17 at 0:26

Binary math is an imperative to understand automation. 36 years on the job with 14 years on podium. Especially today where the the world is full of assumptions. All new employees I have had could not conceive how the physical inputs and outputs work in relationships to the masterful programming they developed.

• Welcome to Computer Science Educators. I have a few requests for edits to your answer. First, what is "on podium"? Also, could you expand on your second sentence?
– Ben I.
Mar 9 '20 at 15:01