I’m learning how to program and my homework often includes number base conversion. I guess my teacher likes that kind of thing! Is there any easy way to convert numbers on a PC? Thanks.
Once computers began being built around simple binary switches – on / off – it was perhaps inevitable that the language of computers would embrace base-2, base 2**3 and base 2**4 numbers too. What are they? Binary (base 2), Octal (base 8) and Hexadecimal (base 16). As your teacher has undoubtedly already told you, the more bits you have for each digit, the less digits are required to express large numbers. 100 decimal (base 10) is 1100100 in binary, but only 64 in hex!
What’s great is that there are a lot of ways you can convert numbers between these bases on your Windows PC, even down to the lowly Calculator program included with Windows 8, Windows 10 and, heck, probably the original Windows 3.1 release. The trick is that the Calculator has a variety of different modes, you just have to hunt for them.
So let’s start there since it’s the easiest. Launch the Calculator on your Win10 computer, then click on the three horizontal lines button on the top left and choose “Programmer” from the list of calculator options:
Turns out there are four major modes for the Calculator: Standard, Scientific, Programmer and Date Calculation. Want to know how many seconds you’ve been alive? You can figure that out with the date calculator. But let’s stick to topic, so choose “Programmer“, as shown above. I did a tiny bit of resizing to make it look neater and… here it is!
Now you can use the number pad and do binary machine-esque calculations like applying an XOR or NOT, but for base calculations it’s way easier: Just click on the base you want to enter then either using the number pad in the app or your own keyboard enter the base number. In this case, I want to convert 7654 Octal to Hexadecimal (“hex” for short).
I’ve done that above: You can see that the answer is FAC or, more accurately 0xFAC using a standard base notation. It’s also convert the octal number to binary – 111110101100 – and decimal – 4012 – instantly too. Want to convert the other way? A click on “DEC” for decimal and we can find out what 2019 is in the various bases too:
So we’re really in year 3743 if, uh, we were living in a base-8 world.
But it doesn’t stop there. You can do conversions directly in Cortana search too. I kid you not:
In this case, you need to know the full number base prefix notation: a zero followed by a letter to denote the non-decimal base. So ‘o’ for octal, ‘b’ for binary and ‘x’ for hex. As shown above, that’s the output format too, so FAC becomes 0xFAC.
You can enter exactly the same query to Bing and it’ll solve it without having to go to a Web site too:
Google can do this nifty little trick too.
If you had access to a Linux command line (and lots of Windows users add the Linux subsystem too) you can also do conversion directly on the command line if you really want to go old school. This involves utilizing a crufty old program called bc, for ‘binary calculator’. Its inputs need to be specified in the input stream, so echo is typically used. Then ibase specifies the input base and obase specifies the output base. Like this:
$ echo 'ibase=8;7654' | bc 4012 $ echo 'obase=16;7654' | bc 1DE6 $ echo 'obase=16;ibase=8;7654' | bc FAC
The first example converts 7654 octal to decimal (4012), the second converts 7654 decimal (no input base specified) to hexadecimal (1DE6) and the third converts octal to hex. Pretty cool, actually. Just beware that you have to specify the obase before the ibase for the more obscure conversions to work.
That’s it. Lots of different ways to quickly and easily convert between common numeric bases!
Pro Tip: I’ve been writing about Windows from both a user and programmer perspective for years. Check out my Windows help library for lots of interesting tutorials.