Recommended Posts

You will often see the terms "Binary" and "Hexadecimal" appear often in programming. From what I hear, professors rarely mention what these *truly* mean. Some would infer that binary and hexadecimal is some special way to count that only applies to programming.

This is actually untrue. The terms "binary" and "hexadecimal" are just special names for something abstract. Because in all reality, they are just a number system that represents the quantity of something. To understand what this means, allow me to explain something.

What are Numbers?

Obvious question right? Numbers are like many things completely abstract. They are just symbols made to represent a quantity of something. In all reality, there is nothing stopping me from saying that an emoji represents 8,654. Numbers are just symbols.

Throughout history, there has been many number systems. Something really weird to us now, but before the concept of a number was represented by at most 6 symbols. How is this? To us, it would seem impossible for something like this to happen. In schools we are taught that counting goes up to 9, then turns into 10. We count to 19, then we go to 20. Basic, right?

This is where base number systems come in. And you may be amazed to learn how limitless base number systems can be.

Base 10

I am going to make this quick because you should already know a lot about this.

Base 10 is what we are all taught in schools. In 2nd grade we are taught about place values and how they can be used to find out what a number is.

For instance, the number 1245 when broken down is this:

one 1000's (or one in the 1000's place)

two 100's (or two in the 100's place)

four 10's (or four in the 10's place)

and five in the 1's place

1000+200+40+5 = 1245

One thing you probably learned in middle school was the fact that place values are actually just exponents. Each place value is one power greater than the previous. In a base 10 number system, X would be equal to 10. And of course, every place value goes up by one power of 10. So for example, place value 7 (which would be 10^6 in the diagram) would be the millions place. Or of course the 1,000,000's place. And as you know, one million is 10^6.

Base 2

Binary. Like I said before, binary is just a fancy name for a base 2 number system.

In the end, there are 10 people in the world. Ones who understand binary, and ones who don't.

Base 2 is the same concept as base 10. However, you might not recognize it right away. Binary has place values just like base 10. The only difference is NOW X = 2.

Remember the diagram? X is a variable. In base 10, X = 10, which means every place value is a power of 10. But in binary? Every place value is a power of 2.

Still confused? Let me show you what each place value represents in base 10: Now base 2: Finding the value of this number is exactly the same process as any other number system. You add the place values together. Let's use the number in the diagram as an example.

Let's calculate:

one 512's

one 256's

zero 128's

one 64's

zero 32's

zero 16's

zero 8's

one 4's

zero 2's

one 1's

512+256+64+4+1 = 837.

This means that 1101000101 when converted to a base 10 number system is equal to 837.

Base 16

Hexadecimal. What you see in machine code and RAM addresses.

When you first learn about hexadecimal you would likely be confused. Because you'd think to yourself: f != 15.

Remember, numbers are abstract concepts used to represent quantity. You can use anything to represent a quantity of something. We just officially use number systems to do it. So yes, f == 15.

If you have any experience with hacking retro games or looking into retro games RAM, you would very quickly identify something like this:

8f

This is what could be stored in a RAM address in the retro games era. The good ol NES. The highest value that could be stored in a single RAM address was ff, or 255. And unsurprisingly, hexadecimal works exactly like everything else.

Everything goes in powers of 16. The first place value is 16^0. The next goes one power up, being 16^1. So this means to represent 15, it would be: 0f

16 = 10

24 = 18

26 = 1a

31 = 1f

32 = 20

And of course, counting up to 254 would bring you to fe. Then once you count to 255, you now have ff.if you count up one more time, your number would become 100.

one in the 256's place

zero in the 16's place

zero in the 1's place

Math With Other Base Number Systems

... Is surprisingly simple. It works just like base 10. Lets calculate what 109 + 32 is.   Seriously, just try to do some math with binary. It's honestly really fun. Not with hexadecimal thought. Screw doing math with hex.

The Use of Base Systems

The bigger the base number is, the less symbols needed to represent a quantity.

For instance, representing the quantity of 255 in binary is:

11111111

In base 10 however, it is simply 255. But, in base 16:

ff

Just simply two f symbols.

And the best thing is, if you wanted a base 256 number system, you could literally represent 255 with 1 symbol. Which means representing the number 256 would look like this:

In binary = 100000000

In base 10 = 256

In hex = 100

In base 256 = 10

As long as you have enough symbols to represent it, you can literally have any base system you'd like.

Thank you for reading bois.

Edited by _Rocket_
Colorz
• 3

Share on other sites

A good trick to be aware of is how to jump between hexidecimal and binary with hardly any math.  Each digit in hexidecimal is four binary bits.

A common convention for hexidecimal is to show the 0x before the digits.  So 0x1 in hexidecimal is 0001 in binary.  0x10 is 0001 0000.  In hardware description language (HDL) such as Verilog you'll make it very clear what you're using by placing the size and the system (in this case an h for hexidecimal) in front such as:

// 32 binary bits and the notation is in hex (there are 8 hex digits, and 4 times 8 is 32 bits)
32'h5a827999

/* without any math tricks you can see the binary version is
*  0101 1010 1000 0010 0111 1001 1001 1001 */

I think you could take advantage of the sub and superscripts in the text editer.  1010 shows up as 21 + 20 + 21 + 20 really well in my opinion.

I'm not sure where you heard that about professors.  I've had multiple professors at multiple universities cover this topic very thoroughly throughout various modules.

Overall a nice guide.  Thanks.

Edited by Joshy

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account. Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

• Recently Browsing   0 members

×
• Home

• Activity

×
• Create New...