“Unraveling the Mystery of Base Conversion: A Joyful Journey from Binary to Hexadecimal and Beyond!”

Tomoharu Tsutsumi
3 min readJun 10, 2023

Mastering the art of base conversion is a pivotal step in understanding computer science. Yet, despite its importance, it’s easy to forget. So, let’s dive into an entertaining refresher!

Converting Base 2 to Base 10:
This one is a breeze! Each digit carries its own weight.
Take for example, 1101. It translates to 2³+ 2²+ 2¹+ 2⁰=> 8 + 4 + 0 + 1 => 13. Voila! You’ve just converted from base 2 to base 10.

Converting Base 2 to Base 8:
Hold on to your hat, because this one is remarkably similar to the base 10 method. The twist is that we pick out groups of three digits from the rightmost side. For instance, 111111 becomes 2²+ 2¹+ 2⁰, 2²+ 2¹+ 2⁰=> 77. Neat, isn’t it?

Converting Base 2 to Base 16:
Now, it’s time for base 16 to make an entrance! This time, select groups of four digits from the rightmost side. So, 11101110 => 2³+ 2²+ 2¹+ 0, 2³+ 2²+ 2¹+ 0 => 1414. Easy peasy!

Now, let’s flip it over.

Converting Base 8 to Base 2:
Transform each digit into binary. For instance, 13 becomes 001011 and simplifies to 1011.

Converting Base 8 to Base 10:
We’re back to using weight digits. So, 13 => 8¹* 1 + 8⁰* 3 => 11. You’re on a roll!

Converting Base 8 to Base 16:
First, flip the number to decimal. Then, divide the number (and each subsequent answer) by 8 until the quotient hits zero. For example, 26 => 8¹* 2 + 8⁰* 6 => 22, then 22 / 8 => 1 remainder 6, and finally 1/ 8 => 0 remainder 1 => 16.

Let’s now bring in Base 16:

Converting Base 16 to Base 2:
Change each digit into binary. So, 5E turns into 01011110, which simplifies to 1011110.

Converting Base 16 to Base 10:
We’ve got the drill by now — weight digits! 12 => 16¹ * 1 + 16⁰ * 2 => 18.

Converting Base 16 to Base 8:
Again, first flip to decimal. Then, divide the number (and each subsequent answer) by 8 until the quotient is zero. For instance, 24 => 16¹ * 2 + 16⁰ * 4 => 36. Then, 36 / 8 => 4 remainder 4, and finally 4 / 8 => 0 remainder 4 => 44.

And lastly, we visit our friend, Base 10:

Converting Base 10 to Base 2:
Continually divide the number (and each subsequent answer) by 2 until the quotient reaches zero. For example, 16 => 16 / 2 => 8 remainder 0, 8 / 2 => 4 remainder 0, 4 / 2 => 2 remainder 0, 2 /

2 => 1 remainder 0, 1 / 2 => 0 remainder 1 => 10000.

Converting Base 10 to Base 8:
Again, keep dividing the number (and each subsequent answer) by 8 until the quotient becomes 0. For example, 127 => 127 / 8 => 15 remainder 7, 15 / 8 => 1 remainder 7, 1 / 8 => 0 remainder 1.

Converting Base 10 to Base 16:
127 => 127 / 16 => 7 remainder 15, 7 /16 => 0 remainder 7 => 7F. Ta-dah!

And there you have it, a fun and painless guide to base conversion in computer science! Now, go ahead and try some conversions on your own — you’ve got this!

Feel free to reach out to me on LinkedIn, which you can find below. Looking forward to connecting!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Tomoharu Tsutsumi

Senior Software Engineer at two industry-leading startups ( Go | Ruby | TypeScript | JavaScript | Gin | Echo | Rails | React | Redux | Next)