Eli5 Binary and hexadecimals

174 views

I’m struggling in class with understanding and calculating😭😭 It’s just not clicking for me

In: 6

9 Answers

Anonymous 0 Comments

Binary is base two.

1 is 1.

2 is 10.

3 is 11.

4 is 100.

Hexadecimal is base sixteen. Works the same as any other base, but we need letters to go past nine, hence A-F for 10 through 15.

What’s nice between binary and hex is that one hex character is four binary characters mushed together.

0 = 0000

1 = 0001

2 = 0010

3 = 0011

4 = 0100

5 = 0101

6 = 0110

7 = 0111

8 = 1000

9 = 1001

A = 1010

B = 1011

C = 1100

D = 1101

E = 1110

F = 1111

So, any binary number can be made into a hex number with 1/4 the characters.

It’s useful to have a high base around, even if you’re thinking in binary. We’re used to ten, but as you’ve seen converting to and from binary and base ten is annoying. Base sixteen makes the algorithm easy: just count every four binary digits, add them up as if it were just those four digits, and add the value to the hex number as one more hex digit. Going the other way is even easier, take the hex number one character at a time and spit out the 4-digit binary equivalent.

Anonymous 0 Comments

They’re different ways of counting up.

In “normal” (decimal) counting, we have ten symbols: 0 1 2 3 4 5 6 7 8 9. We start counting up at 0, and when we get to 9, we’re out of symbols, so the system we use is to put a 0 there, put a 1 one space to the left, and then start counting up again. Repeat as long as necessary.

In binary, there’s only two symbols: 1 0. Again we start counting up at 0, but as soon as we hit 1, we’re out of symbols, so we again place our 1 one space to the left, and start counting up again.

In hex, we instead have sixteen symbols: 0 1 2 3 4 5 6 7 8 9 A B C D E F. Now we don’t have to move over one space until we’ve counted up to F, where you start over at 1 again.

As it turns out, using binary is useful for computers, because they’re all based on circuits that have two states: on (1) and off (0). Decimal counting is arbitrary, but works well for beings with five fingers on each hand. Hex is useful for fitting larger numbers in less space, which is why they’re common in computing.

Anonymous 0 Comments

They’re both positional number systems–much like the one you’re used to.

Base-10, which is what the normal number system is called, allows for 10 separate characters (0 through 9) to represent 10 separate values.

When the value you’re trying to write down exceeds the maximum value of the position you’re filling, the value rolls over to the next column and the current column reverts to the minimum value.

So, 9 + 1 exceeds the maximum value for one column in a base-10 system. So the value rolls over; 9 becomes 10.

This is true over any number of columns. 99 + 1, for example, goes like this:

99 + 1 = 9 {10, which exceeds the maximum value}, so that rolls over again to {10}0. That 10 also exceeds the maximum value, so it rolls over *again* to 100. This is the basis of “carrying,” as it’s commonly referred to.

You may have seen binary or hex written as exponential values… this is true for base-10 and all other systems, too. The more generic way of writing this is base^position . The “ones” column in a normal number is essentially 10^0 times whatever the value in that column is; the “tens” column is 10^1 times whatever the value in that column is, etc.

So, written like that, “100” becomes “1*10^2 + 0*10^1, + 0*10^0 “. A more complex number, say 2093, would be “2*10^3 + 0*10^2 + 9*10^1 + 3*10^0 “.

As I said, this is true for all bases. In a base-4 system, the maximum value character would be 3, so the (base-10) value “100” would be “1210” in base 4, because that works out to be 1*4^3 + 2*4^2 + 1*4^1 + 0*4^0. You can check that if you want–it works out to be 64 + 32 + 4 + 0 = 100.

So, binary and hexadecimal. These are simply popular bases to work with. Binary is base-2, hexadecimal is base-16.

So, in binary, the base-10 value “100” is just “1100100”. We can do the same math to check this: 1*2^6 + 1*2^5 + 0*2^4 + 0*2^3 + 1*2^2 + 0*2^1 + 0*2^0. That works out to be 64 + 32 + 0 + 0 + 4 + 0 + 0 = 100.

Hexadecimal is exactly the same… except that we don’t have number characters to represent values higher than 9, so we use letters. 0 through 9 are the same; 10 is represented by A, 11 by B, and so on. Hexadecimal is base-16, so the characters are 0 through F.

In computers, you may even come across “octal”, which is just base-8.

Anonymous 0 Comments

Consider that number places are like little containers, and the containers can only hold [this many] items before getting full up. After one container is full up, we empty it and say “well, that’s one full up container,” and we mark that by putting one item in the second container. Our containers look like this now: 1|0 or (10).

In “normal” counting (that is, base ten, or decimal)
a container can hold no items, or one item, or up to nine items.
When it has nine items, it is full up, and before we can add another item, we empty the container, and mark that by putting one item in the next container, signifying there’s been one full container.

Say you have twentysix beans.
You put nine of them in the right-most container, and when you pick up the 10th bean, you put it in the second-right-most container, and you empty the rightmost container. This is the number 1|0, 10, ten.

You fill the rightmost container with another nine beans, and when you pick up the 10th bean, you put it in the second-rightmost container, which now has two beans, and you empty the rightmost container. This is the number twenty. 2|0 (20)

You add six beans to the rightmost container.
You now have the number twentysix. 2|6 (26)

**Binary** is just like decimal, but the container gets full up with just one bean. When you go to add the second bean, there’s no room in the rightmost container, so you empty it and mark in the secondrightmost container that you’ve had one full up container. Two beans, written in binary, is 1|0 (10). That looks like ten, but it takes a while to get used to, and yeah, it is a little weird.

Add one more bean to total three beans, and you have the binary number 1|1 (11). Two containers that are full up.

Add a fourth bean. You go to add it to the rightmost container, but that too is full up, so you empty that container and go to the secondrightmost container to mark another full up container, but the secondrightmost is full up as well, so you empty it and go to the *next* container. You now have the number 1|0|0 (100), which is four.

Anonymous 0 Comments

This may be a bit more middle school than 5, but the thing that helped me a lot when we did different number bases in school was to remember “places”. When we’re first learning to count they make a big deal of One’s, Ten’s, Hundred’s, places. Because the way we learn how to count is using base 10, or decimal, each “place” in a number is a power of 10. (10^0, 10^1, 10^2) But after a few years they stop talking as much about 10’s and 100’s and saying stuff like “3 1’s and 2 10’s” so it’s easy to forget about places.

So we have places and we also have numerals indicating a value multiple. In base 10 we have numerals 0-9 because we need 10 values.

So now we have values and places. We have 10 values because each place represents a multiple of 10, so we need 10 possible values in each place to be able to represent numbers in order without skipping any.

We may have just internalized converting 436 to base 10 as “counting” but we could also learn to convert it like this:

Starting from the right read the value in each place.

Place | Value
———|———-
1|6
10|3
100|4

Multiply the value in that place by the place it’s in and add that result to all previous results:

`(6*1)+(3*10)+(4*100)=6+10+400=436`

Yeah now you know how to read numbers, so what?

Well the same longhand process I described will let you read numbers in _any_ base.

Let’s look a hex value like: 1B4

Places in hex are 1’s (16^0), 16’s (16^1), 256’s (16^2)

Place | Value
———|———-
1|4
16|B
256|1

And now the math:

`(1*4)+(16*B)+(256*1)=4+176+256=436`

Same number.

Note that B gets treated as if it was 11 (base 10) because after 0-9 we just keep going with letters using increasing decimal values so A=10, B=11, etc.

Binary is the same method except your places are based on powers of 2. 2^0 = 1, 2^1 = 2, 2^2 = 4.

Edit:

Thinking in places also lets you relearn how to do calculations directly in bases. Like if you remember adding decimals you add the 1’s together, then carry the 1 to the 10’s place, then carry the 10 to the 100’s place as you add numbers that overflow the “space” they’re in.

In hex `1B4+10=1C4`because you just add the places together.

Place | Left side | Right side | Result
———|———-|——–|-
1|4|0|4
16|B|1|C
256|1|0|1

Or here’s one that needs to carry a number to the next place

Place | Left side | Right side | Result
———|———-|——–|-
1|4|C|0 (C=12, 4+12=16 which is larger than a single numeral in hex can express)
16|B|1|C (Carry the 1) = D
256|1|0|1

Or 1B4+1C=1D0.

Anonymous 0 Comments

Say I have 6 rocks and I want to make a nice sign telling people how many rocks I have but I am some strange alien who only has 2 symbols for numbers.

Lets start counting and writing it out using our symbols which don’t exist on a human keyboard so I will use X and Y:

X (we are starting out at zero)

Y (1)

YX ( 2, damn I ran out of symbols so had to make the thing wider)

YY (3, making the thing wider means I can use my old Y position that means 1, 1+2=3 cool)

YXX (4, damn ran out again, gotta make it wider again)

YXY (5, got to add that one again)

YYX (6, I wanted to add a 2 to a 4)

You can abstract over any source of truth, our rocks, and count them in a system of any bases. You have just existed in base-10(symbols are 0-9) your whole life and base-2 (0-1 or X/Y if you want to hammer home symbols only have the meaning we give them) is how computers see the world we made a weird compromise on base-16 for hex (it is about bytes) which we can both sorta understand

Anonymous 0 Comments

Well, let’s start with the number systems you probably already know:

* The simplest is to count on your fingers or use tally marks. For example, we could write the number four as “IIII”. To help make large numbers easier to read, maybe we’ll draw each fifth tally mark horizontally. So, for example, the number twelve might be “~~IIII~~ ~~IIII~~ II” in tally marks.
* To make them quicker to write, we could simplify the symbols. Let’s represent five as a stylized hand: “V”. Two “V”s can be stacked together, one upside-down, to make “X”. We’ll represent a hundred as “C” (short for *centum*, which is Latin for “hundred”) and a thousand as “M” (short for *mille*, which is Latin for “thousand”). The bottom half of a “C” looks kind of like an “L”, and the left half of an “M” looks kind of like a “D”. So, for example, the number two thousand six hundred and eighty-seven could be represented as “MMDCLXXXVII” in Roman numerals.
* We’re going to eventually run out of letters. (What should ten “M”s be? The Latin word is *myrias* and the English word is *myriad*, but we’ve already used “M”, and “Y” is too similar to “V”.) So instead we come up with a place system in which we reuse the same symbols over and over again and their meaning depends on position: the rightmost symbols will tell the number of ones, the next will tell the number of tens, and so on. So, for example, five myriad three thousand six hundred and sixty-five could be represented as “53649” in decimal.

Now we can move forward:

* Having even just ten separate symbols is actually a lot in some contexts. In particular, electrical switches tend to have only two possible states: on and off. So if you’re trying to communicate a number to somebody by turning your lights on and off while they watch your window from across the street, it’s not going to work to need ten different symbols. So instead we take the idea of places, but with only two symbols: 1 and 0. The rightmost will tell the number of ones, the next will tell the number of twos, the next the number of fours, and so on. For example, the number two hundred and thirty is equal to 1*128+1*64+1*32+0*16+0*8+1*4+1*2+0*1 (there’s no shortcut for knowing this, you just have to do the arithmetic to figure out how many of each power of two you need), so can be represented as “11100110” in binary.
* If we’re in a context where we do have the ability to use more symbols, maybe we want to use a number of symbols that’s easily convertible into and out of binary *without* having to do a bunch of arithmetic. Sixteen is convenient, since in binary it’s the nice round number “1,0000”. So in addition to “0” thru “9”, we’ll use “a” to represent ten (which in binary is “1010”), “b” to represent eleven (binary “1011”), and so on up through “f” for fifteen (binary “1111”). For example, the number five myriad one thousand two hundred and seventy-four is equal to 12*4096+8*256+4*16+10, so can be represented as “c84a” in hexadecimal (to convert it to binary, since each symbol can be represented as four bits, and since each symbol’s place is “1,0000” times the previous symbol’s place, we can just convert each symbol individually: c is “1100”, 8 is “1000”, 4 is “0100”, a is “1010”, so “c84a” in hexadecimal becomes “1100,1000,0100,1010” in binary).

Anonymous 0 Comments

There’s other good answers about the system itself, so I’ll focus on the ‘calculating’ part of the question (sorry if I misinterpret what you are asking).

The math you already know works pretty well with other number systems. 1*n = n, 0*n = 0. 10*10 = 100. It’s just the in betweens that might trip you up, but if you don’t need to solve in the fewest amount of steps you can just convert the numbers into something that makes sense to you.

Here’s a simple example: in binary, 0b10 represents 2 (the leading 0b tells everybody the rest of the number is **B**inary, which is important if you want to switch back and forth). So 0b10*0b10 converted to decimal is 2*2, or 4. And the answer you would have had if you stayed in binary, 0b100, is the correct conversion for 4.

This also works with more complex numbers:

* 0b101*0b101 =
* 0b101(0b100 + 0b1) =
* 0b101*0b100 + 0b101*0b1 =
* 0b10100+0b101 =
* 0b11001
* or 5*5 = 25, which converts back to 0b11001.

Hexidecimal can be intimidating, and generally not worth trying to calculate by hand without converting to decimal; we needed memorizing times tables in order to get it done with decimal, and practically nobody is willing to do that when we have computers everywhere anyway. If you need to multiply 0xB*0xB, you might as well change it to 11*11 = 121 = 0x79, or 7*16+9 (the leading 0x means he**X**idecimal).

The only shorthand I can give you for hex calculations is that 0x8 is like decimal’s 5, and 0x4 is kind of similar to even numbers: multiplying by 0x8 will always result in a 0x…8 or a 0x…0, while 0x4 will always result in 0x…0, 0x…4, 0x…8, or 0x…C. These two facts are used in 4-byte or 8-byte address locations and accessing them, but that’s a programming thing.

Anonymous 0 Comments

Computers can only understand if something is on, or off. If it’s on, it’s a 1. If it’s off, it’s a 0.

You have 8 digits, or bits, in a byte. If you turn the first bit on, it’s a 1. From right to left, you’ll notice that they are powers of 2, or just double what was previous. So it goes:

128 | 64 | 32 | 16 | 8 | 4 | 2 | 1

Now, when you see a binary number, in this example 00000001, you just line it up with this “graph.” Since the first bit is on, and it equals to one, this means 00000001 = 1.

If you have 0101, you’ll notice it’s only half a byte. You can substitute the remaining 0’s if you want, but 00000101 and 0101 equal the same thing, 4 + 1. Since the 3rd and 1st bit are on. So, 5.

Hexadecimal if I remember correctly involve the numbers 1-9 and letters A-F. The letters A-F are just 10-15. So:

A = 10

B = 11

C = 12

D = 13

E = 14

F = 15

So, when you see 35, you naturally read that as thirty five, but in hexa it’s actually 3 and 5. Remember that half byte I talked about earlier? It applies here. You may notice that with a half byte the max number you can reach is 15, which is the max for hexa too. So each number is split into 2 half bytes, to make 1 byte. In this case you convert 3 to binary, and 5 to binary.

You convert by going from right to left, turning on bits until you reach the desired number.

For example, 5 is 0101, and 3 is 0011, you put these together and it is 00110101, or 35, three and five.

Another example, 4F. F is 15, and 15 is all of the bits in a half byte turned on. So it’s just 1111. 4 has its own bit, so it’s 0100. Together? 01001111.