Become a better software engineer by learning about different number bases
A brief introduction to Number Bases in software engineering and computer science
Almost every Computer Science student goes through Number bases at some point in their careers. However, the focus is generally on the how (how to switch between number systems, doing arithmetic with different bases etc). There are tons of great resources to learn the same (I like this guy on YouTube). Instead of reinventing the wheel, I want to touch upon where each number system might be useful to a software engineer or computer scientist.
If this sounds interesting to you, let’s get right into it.
A quick introduction to the various number systems
Binary, The Building Blocks of the Digital Universe: Ultimately, everything starts with binary, the bedrock of computing. Every transistor, every bit of data, every instruction within a computer boils down to the simplicity of 0s and 1s. Let’s touch on the important uses of binary numbers in programming.
Notably, understanding binary becomes imperative for tasks like optimizing assembly code, writing device drivers, and interfacing directly with hardware. “On simple low-cost processors, typically, bitwise operations are substantially faster than division, several times faster than multiplication, and sometimes significantly faster than addition.” Aside from Bitwise Ops, Binary is the basis of storage protocols like ASCII and has some interesting applications in compression. Finally, we also have error correction, which also leverages binary numbers. Studying all of these can be very helpful to take your software to the next level.
Octal, Bridging the Gap Between Human and Machine:
Binary can get really long and unreadable. Grouping binary digits into sets of three, octal (base-8) offers a more concise and human-readable representation of binary data. Octals also show up for file permissions and network protocols in the UNIX system. As computing has shifted to 16/32/64 bit words, Octals became less useful. Except for some niche cases, you don’t need really need to go out of your way to study them (this is a pretty fun list of some ways Octal numbers have been used though). But you might occasionally run into problems when building something on a system b/c that system uses Octal. So it was worth mentioning it here.
I’m writing a JIT compiler for x86_64, and three-bit octal literals are a godsend. I can construct otherwise complicated ModR/M and SIB values using straightforward math (no bit-shifting) even though they are composed of packed three-bit values.
My favorite use of 8-bit vectors is their usage in detecting malware. The solution hinges on the fact that image classification is a relatively solved problem, so we turn the malware binary to an 8-bit vector, which is then turned into a grayscale image. We can train classifiers on these images (+ analyze them ourselves), which improves our performance significantly. This is something you can extend to various challenges (I have done this with great results), but it requires some setup.
Hexadecimal, for Memory and Color Palettes: Next, we encounter the hexadecimal base, which is clutch for memory management and color representation. “Memory is often manipulated in terms of larger units, such as pages or segments, which tend to have sizes that are powers of 2. So if addresses are expressed in hex, it’s much easier to read them as page+offset or similar constructs. Decimal is difficult because of that pesky factor of 5, and binary addresses are too long to be easily readable.” This is also similar to why we use Hexadecimal to represent colors
P-adic Numbers, The Untamed Wildcards of the Counting Game: P-adic arithmetic is a method of representing and performing arithmetic on real numbers using a different number system based on the prime number p. In software engineering, p-adic arithmetic allows for error-free representation of fractions and error-free arithmetic using fractions, which can be advantageous in certain computational tasks. There are two main types of p-adic arithmetic: “infinite-precision p-adic arithmetic which is more suitable for software implementations and finite-precision p-adic arithmetic which is more suitable for hardware implementations. The finite-precision p-adic representation is also called Hensel code which has certain interesting properties and some open problems for research.”
If you’re looking to bring some beauty to you life, p-adics will help a ton there too-
P-adic numbers are pretty good for fractals, which aside from having various applications, just look really cool. I remember spending a few hours experimenting with fractals and playing with different representations when I first learned about them (that was my version of stable diffusion/AI art generators). It seems like p-adic numbers might have some potential in embeddings, but there is a lot of math I have to learn before I can make any conclusions .
If you are looking for skills to add into your toolbelt as a software developer, understanding the various number bases and the role they play is key. More than the implementation details, it can be beneficial to read into each use case in a lot of detail to build up your pattern recognition skills.
If you liked this article and wish to share it, please refer to the following guidelines.
Save the time, energy, and money you would burn by going through all those videos, courses, products, and ‘coaches’ and easily find all your needs met in one place at ‘Tech Made Simple’! Stay ahead of the curve in AI, software engineering, and the tech industry with expert insights, tips, and resources. 20% off for new subscribers by clicking this link. Subscribe now and simplify your tech journey!
Using this discount will drop the prices-
800 INR (10 USD) → 640 INR (8 USD) per Month
8000 INR (100 USD) → 6400INR (80 USD) per year (533 INR /month)
Reach out to me
Use the links below to check out my other content, learn more about tutoring, reach out to me about projects, or just to say hi.
Small Snippets about Tech, AI and Machine Learning over here
AI Newsletter- https://artificialintelligencemadesimple.substack.com/
My grandma’s favorite Tech Newsletter- https://codinginterviewsmadesimple.substack.com/
Check out my other articles on Medium. : https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Reach out to me on LinkedIn. Let’s connect: https://rb.gy/m5ok2y
My Instagram: https://rb.gy/gmvuy9
My Twitter: https://twitter.com/Machine01776819