10 - Conventional Thinking
Bits and Bytes
I’m going to be short on time these next several weeks as I juggle an assortment of endeavours before leaving the country for the entirety of August. So, let’s keep this short-ish and get into some trivia!
In coding, there are certain small things that I do or write that I often take for granted. As with anything, I believe it’s important to ask oneself “why are things this way?”. Often the answer given by those doing/using the thing is “this is the way it’s always been” without much more behind it. That answer has never satisfied me, and I hope it doesn’t satisfy you either. Now more than ever, we need more thoughtfulness and critical thinking.
We’ll be circling back to a few conventions/topics/tidbits that I realized have gone unaddressed in the code snippets I’ve provided previously. Whether you’re a seasoned software developer or a creative who has never looked at code, I believe you’ll find something interesting and new to you throughout this series!
Why is 0-255 a frequently used range for number values?
In p5.js and many, many other places, you’ll see a default number range of 0-255 used. In many cases (but not always) this is dealing with colour, such as representing the amount of red, green, and blue being given to a function like background(r, g, b) or fill(r, g, b). This range is the result of one of the fundamental principles on which computers operate - 1’s and 0’s, or binary!
For the uninitiated, binary is a numerical system that uses powers of 2 to count up.
Let’s do a quick review of how the positional number system works (don’t be afraid, you use a subset of it every day!).
Decimal numbers, the ones we use on a daily basis, are base-10. That is to say, the position of each digit corresponds to the multiplication by a power of 10. The position of each digit starts counting from the right, and the exponent increases by 1 for each position, starting at 0.
You can see that 10 is the base which we apply the exponent to, and then multiply by the digit in the given place.
This is how most number systems you’ll encounter work, including binary and hexadecimal, which are base-2 and base-16, respectively.
Representing 255 in binary:
While we’re at it, hexadecimal (where the set of digits is 0123456789ABCDEF with A-F representing 10-15):
You may be starting to realize where we’re going with this. In a computer, a bit is a single binary value - 0 or 1. 8 bits is called a byte, which is one of the smallest units of storage that a computer uses. Setting every bit in a byte to 1 gives us exactly the top of our range - 255 (decimal)! Maxing out two digits of hexadecimal also gives us the same.
Especially in the early days of computers when memory availability was scarce, programmers had to make pretty strict decisions with respect to how data was stored and represented. Using a single byte as the value range allows for a good balance between efficient storage and sufficient resolution for the threshold of perception of colours by the human eye. This convention has held for quite some time and is still in use today, although more and more displays support higher-bit representations for colours (such as 10 or 12-bit) to further increase colour/brightness resolution and handle subtle gradients, particularly in cases such as High Dynamic Range (HDR) displays.
If you’ve ever worked in graphic design, web design, or UX, you’ve probably come across what are commonly referred to as “hex codes”. Now that you know how the hexadecimal (base-16) system works, hex codes should be pretty self-explanatory. They’re often prefixed with a # to indicate that they’re a hex code, and are always comprised of 3 bytes (aside from rare occasions where they also represent alpha/opacity, in which a 4th byte is added) shown in hexadecimal representing the red, green, and blue values of a colour.
#FFFFFF → (FF = 255, FF = 255, FF = 255) = white
#000000 → (00 = 0, 00 = 0, 00 = 0) = black
#850000 → (85 = 133, 00 = 0, 00 = 0) = dark red
#00DEDE → (00 = 0, DE = 222, DE = 222) = turquoise
There you have it - that’s why 0-255 is a very common range for number values in coding.
Now you know!
Weekly quote:
“It may seem hopeless. It may appear as if we’re merely witnessing a long series of negative steps that will eventually crush freedom and outlaw opposition. But it doesn’t have to be this way. We can unite and seek out more people who see the threat in these trends. They do exist and they are everywhere, even within the government itself. What better way to prove that you believe in free speech, free association, the Constitution, civil rights, etc. than to stand up and fight for them when they become endangered? We look forward to the battles ahead.”
~ Emmanuel Goldstein, “Stick Around”, 2600 - The Hacker Quarterly (Vol. 21 No. 4, Winter 2004-2005)
Album of the week: “Cosmic Surgery” (2011) by neat beats
If you have any feedback or questions about this or any other post (or just want to say hi!), I’m always happy to chat. Thank you for taking the time to read!


