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?
-
4$\begingroup$ Can you specify your audience? Is this 1st year high school or university? Is the course for Computer Science majors, or everyone? $\endgroup$– KanekiCommented Jun 22, 2017 at 19:26
-
2$\begingroup$ 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. $\endgroup$– Sean HoulihaneCommented Jun 22, 2017 at 23:23
-
5$\begingroup$ 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. $\endgroup$– Loren PechtelCommented Jun 23, 2017 at 4:26
-
9$\begingroup$ Wait, you mean they haven't been taught number representations in high school? I'm truly shocked. $\endgroup$– Jörg W MittagCommented Jun 23, 2017 at 6:50
-
3$\begingroup$ @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! $\endgroup$– xDaizuCommented Jun 23, 2017 at 9:51
12 Answers
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. :)
-
7$\begingroup$ 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. $\endgroup$ Commented Jun 23, 2017 at 13:14
-
2$\begingroup$ @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. $\endgroup$– WildcardCommented Jun 23, 2017 at 13:24
-
8$\begingroup$ 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. $\endgroup$ Commented Jun 23, 2017 at 13:36 -
1$\begingroup$ 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. $\endgroup$ Commented Jun 23, 2017 at 16:47
-
1$\begingroup$ Most students taking a computer science degree have zero intention of being a computer scientist. 95+% of them are going to be maintaining poorly written internal apps for some big company. $\endgroup$– corsiKaCommented Jun 24, 2017 at 17:00
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...
See also this cartoon.
-
8$\begingroup$ I always make that joke about 132. :) $\endgroup$– Ben I. ♦Commented Jun 22, 2017 at 21:58
-
1$\begingroup$ I'm very careful about that in the HS classroom. $\endgroup$ Commented Jun 23, 2017 at 16:51
-
1$\begingroup$ Good point, @AlfredThompson. I teach at a women's college, where the students are more mature than high schoolers. $\endgroup$ Commented Jun 23, 2017 at 17:54
-
3$\begingroup$ @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. $\endgroup$ Commented Jun 24, 2017 at 0:57
-
3$\begingroup$ 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. $\endgroup$ Commented Jun 24, 2017 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 toInteger.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 negateInteger.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?"
-
1$\begingroup$ 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. $\endgroup$– thesecretmaster ♦Commented Jun 23, 2017 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.
-
-
$\begingroup$ @BenI. Thanks! Please feel free to let me know if my answer could be improved. $\endgroup$ Commented Jun 22, 2017 at 20:36
-
2$\begingroup$ 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".) $\endgroup$ Commented Jun 23, 2017 at 3:31
-
$\begingroup$ Ah, sorry, my answer isn't completely clear there. I'll figure out how best to update that. Thanks! $\endgroup$ Commented Jun 23, 2017 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.
-
$\begingroup$ Our first real Computer Science Problem: How do you change base representations of numbers. Here is a big fat place to introduce mod (%). $\endgroup$ Commented Jun 22, 2017 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.
-
4$\begingroup$ 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. $\endgroup$ Commented Jun 22, 2017 at 23:16
-
2$\begingroup$ @SeanHoulihane - boolean logic is literally about binary states. $\endgroup$– DavorCommented Jun 23, 2017 at 8:44
-
4$\begingroup$ @Davor yes, as in 2 state logic (or sometimes 4). Nothing to do with power of 2 number systems. $\endgroup$ Commented Jun 23, 2017 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.
-
$\begingroup$ Changing base representations of numbers is an excellent early example of a non-trivial algorithm. $\endgroup$ Commented Jun 26, 2017 at 0:26
(I see that a few answers, though not the accepted one, refer to floating point arithmetic.)
I'm probably in the minority that I teach to engineering-type students, so most of my examples are in floating point numbers. And without understanding binary, how are they going to understand that the following happens
5^2 * (1/5 * 1/5) -1 = 1.192093e-07
5^2 * (1/5 * 1/5) -1 = 2.220446e-16
(for single & double precision respectively) and what this has to do with the fact that single precision has a 23 bit mantissa and double 51?
Ok, I'm not sure that I would bother first-years with this, but second definitely.
-
1$\begingroup$ I think you meant to do
- 1
somewhere. $\endgroup$ Commented Dec 20, 2021 at 21:50 -
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.
-
$\begingroup$ 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? $\endgroup$– Ben I. ♦Commented Mar 9, 2020 at 15:01