A while ago I released BitMarkers - binary stitch markers for knitters and crocheters. I didn't worry too much about a supporting how-to or blog page, because there are a lot of binary number tutorials on the interwebs. But after seeing that the most popular ones tend to dive straight into exponential notation and math-heavy explanations, I decided to go ahead and write my own. This is intended for beginners, and focuses on re-learning how numbering systems work in hopefully a more intuitive way. Then it goes into exponents at the very end.
To put everything in context, let's first review a "normal" number.
Each digit in our number can be 0 through 9. So including 0, there are 10 possible choices for each digit. This is called a base 10 numbering system, and is colloquially known as "decimal". It's also called the "Hindu-Arabic numeral system" after its origins.
In binary, there are only 2 possible choices for each digit: 0 or 1. So it's known as a base 2 numbering system, or binary.
Why only 2 choices? It all boils down to how computers work, electricity, and voltage. Computers can sense the presence of a voltage, or the absence of a voltage. It's either there or it's not. Presence/There = 1, Absence/Not There = 0. So if that's the medium you have for storing and reading information - basically either something's there and it's a 1, or something's not there and it's a 0 - you have to develop a language where you can communicate concepts based on long strings of 1's and 0's. This language is binary.
Binary Counting Method 1 - Rolling over Bits
I think the simplest way to think about counting in binary is to compare it to counting in decimal. What happens when we go from the number 9 to the number 10? Our "9" digit resets to 0, and the next digit rolls over to 1.
The same thing happens with binary. But since we only have 2 numbers possible with each digit, the rollover happens much sooner, at the number 2.
...and the digits just keep counting up and resetting and rolling over:
Each binary digit is called a "bit". 8 bits are called a byte. So if you have 128 GB of memory on your phone, you can store 128,000,000,000 bytes. That's 1,024,000,000,000 bits!
Binary Counting Method 2 - The Places
Another way to think about numbers is by their places. In a 3-digit decimal number, we have the ones, tens, and hundreds places:
We're so used to counting in decimal that we just know 198 = 198. But if we were explaining it to an alien, we could break it down like this:
Whoa! Only having 2 numbers per digit makes each digit rollover sooner and it looks confusing because we don't natively speak binary. But look up at the previous section - remember how 100 = 4? Does it start to make sense that the third digit would be the fours place? Let's break this number down!
Binary Counting Method 3 - Exponents
This is what most tutorials teach because it's technically the "truest" way of converting between numbering systems. But it's also the most mathy, and if you're not a mathy person, it can be confusing to start with this explanation. However, you've already read the above two methods, so you're totes ready for exponents.
Most of us are reasonably familiar with an exponent of 2, so we'll start there. If a number has an exponent of 2, it means the number is "squared" or that you multiple the number by itself.
Another way of thinking about an exponent of 2, is that it means 2 of the number are multiplied together.
An exponent of 3 means 3 of the number are multiplied together.
If you keep adding one to the exponent, you keep adding another multiplication by 3.
3^4 = 3 x 3 x 3 x 3 = 81
3^5 = 3 x 3 x 3 x 3 x 3 = 243
(The symbol "^" is also called "carrot" which means "to the" or indicates an exponent).
But what happens if the exponent is 1? Or 0?
It's a little weird, but just think of it this way.
Now we're ready to explain to our alien visitor how decimal numbers work using exponents, because each digit's place can also be thought of in terms of exponents.
We can go through the same exercise of calculating the value of each digit, using exponential representation.
Ready for the same thing with our binary number?
Ok, same steps:
A few years ago when I was developing the SkeinMinder, I was trying to figure out how to make a normal 2x16 character LCD display larger numbers. Number size is kind of important - I was building a device that would sit on a table-top, and I wanted someone standing above it to easily be able to see the rotation count at a glance, maybe even from a few feet away, without squinting. It was a small conundrum. I didn't want to delve into getting a graphic LCD up and running, I had plenty of other dev work and that seemed like a can of worms I didn't have time for. I've since developed a graphic LCD library (more on that in a future blog post), but at the time, I just wanted to keep it simple. Besides, 2x16 LCDs are plentiful and cheap, they don't require many processor pins, and the LiquidCrystal Arduino library made them easy to get up and running. But oh that fixed font!
I googled around, and found that of course I wasn't the only one who wanted to bend a 2x16 LCD to their will. I think I ran across this instructable by mpilchfamily and this post by digimike, where I learned you can load 8 custom characters into most LCDs, and then write them anytime. They used those characters to create their own big numbers, which look like this:
I liked the bold clarity of the big numbers featured in that code, but they just took up too much space for me. They're 3 columns wide x 2 rows tall, and I really wanted ones that were 2 columns wide x 2 rows tall, so I could fit some normal LCD text plus 4 digits of big numbers on the 2x16 display. Sounds like a good excuse to bust out some graph paper and develop a font, am I right?
One thing I figured out is that 8 custom characters are nice, but man, 9 would have been perfect. JUST ONE MORE would have made 4 L's to make a full zero, 1 vertical bar left, 1 vertical bar right, 1 horizontal bar top, 1 horizontal bar bottom, 2 C's to make 8's and 5's and 2's. OK, so that's actually 10, but I figured out I could live without one of the vertical bars. So that's 9. Maybe I was being too strict with my font style, or maybe I had a mental block, but I couldn't quite make a bold style without coming up one short. Time to get creative. I looked at the built-in symbols, and figured I could make a stylistic zero, using one fully lit character.
I developed 4 fonts overall, the original above I called TREK because of the square clean lines (though it's more original motion picture or DS9 than TNG). TRON incorporates one fully lit character into each number, and made me think of 80s sci-fi movie poster fonts. NASA is reminiscent of the beloved (be-hated?) worm. And then I modified NASA to be a little fancier and gave it some serifs, and that's where my sci-fi inspiration ended because I just called it SERIF. Overall, I think TREK is the cleanest, and easiest to read at a distance, but I kind of love the styling of TRON.
Cool! So I made a sweet font, implemented it for my particular purpose, and promptly forgot about it for a few years. Then I was visiting my friends at Questionable Origin, and we needed to display an estimated battery % for an electric spinning wheel that fits in a Pelican case (if the last few words just blew your mind, do click on that previous link). I busted out my old code, copied it into its own library, and came up with a new % character. At this point, I figured that Big Numbers could probably be useful to a ton of other people, so I worked on tidying it up, put it in more of a standard Arduino library format, and added the ability to handle negative numbers, as well as easily specify the position of the big number on the LCD. And added some example sketches.
It was of course a bigger project than I anticipated, mostly because I wanted it to handle some situations intelligently. I feel that the "-" sign should appear and disappear without the number itself shifting left and right (too distracting). I also feel that there should be inherent leading zero blanking (though if leading zeros are useful in your application, it's easy to comment out the few lines of zero-blanking code). I also thought you should be able to send it just a number and have that number appear in the same place every time without having to specify position, but also be able to override the defaults and place a number in a specific position. A few overloaded functions later, I give you BigNums2x2. It should also be picked up by the Arduino library bot shortly.
I hope you find it useful and easy to use! I'd love to see what you make using the library, please give me a shout-out on instagram @alpenglowyarn and #bignums2x2. And of course, let me know if you encounter any bugs.
Read the Comments or Leave one