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?
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 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.
I give extra credit in Computer Architecture for counting up to 31 on one hand. Just be careful...
See also this cartoon.
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?
intcan only store numbers up to
Integer.MAX_VALUE, after which it wraps around to negative values.
Student: Huh? Why do we call it
intthen? 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_VALUEis -2147483648; why isn't it symmetric? What happens if we negate
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?"
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.
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.
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.