binary, hex, octal and decimal

754_{10}

Numbers are abstract concepts that we represent with digits from a numbering system. There are many ways to represent numbers such as Roman Numerals ( I V X L C ). Our number systems, however, are POSITIONAL systems where the position of a digit signifies a value based on the number base.

The base of a number system is arbitrary, except that some bases are more "natural" for some situations. Our most familiar number base is 10 (decimal), probably used because we have 10 fingers (digits).

A computer doesn't have 10 digits - it uses only the digits one and zero because it has electronic switches that can either be ON (1) or OFF (0) so it is 'natural' to use the base 2 system with computers.(binary number system)

Since binary is difficult to understand as the digits increase, we use hexadecimal (base 16) as a shorthand notation. It simply groups 4 binary digits and expresses them as a single hex digit (0-9, a-f).

Sometimes digits are grouped into sets of 3 digits which allows us to use octal (base 8) as a shorthand for binary using only the digits 0 thru 7. This dates back to the day of 6-bit bytes.

The systems we use are positional such as our own decimal (base 10).
Here 4 places are shown:
1000 100 10 1
---- --- -- -
10^{3} 10^{2} 10^{1} 10^{0}
There are 10 digits in base 10, 0-9. Notes there is NO digit "10"
Generally, for base 'n', we have: n^{3} n^{2} n^{1} n^{0}
In m digits, we can only represent n^{m} patterns.
The range of numbers using this system is always 0 thru n^{m}-1
License Plate Example: 909 518 | AZ9 14F | 01234 | ACE32 9OYTP

BINARY ======^{7} 2^{6} 2^{5} 2^{4} 2^{3} 2^{2} 2^{1} 2^{0}
Using the unsigned binary number system:
1_{2} is 2^{0} = 1_{10}
10_{2} is 2^{1} = 2_{10}
100_{2} is 2^{2} = 4_{10}
1000_{2} is 2^{3} = 8_{10} etc..
Further:
0000 0111_{2} => 4 + 2 + 1 = 7
0001 1011_{2} => 16 + 8 + 2 + 1 = 27
1000 0000_{2} => 128
0100 0011_{2} => 64 + 2 + 1 = 67
So with 8 bits we can represent 2^{n} => 2^{8} => 256 unique codes (0-255)_{10}.
WHY is binary important?
Are we restricted in any way by using binary vs. decimal?

HEX ===

BINARY ======

10100101_{2} = 165_{10}

In base n=2 (binary), the place values we assign for 8 digits (bits) are:
128 64 32 16 8 4 2 1
--- -- -- -- - - - -
2HEX ===

001 0010 0011 0100_{2} = 1234_{16}

Hexadecimal is simply a shorthand notation for binary.
Break binary number into 4 binary digits and substitute:
HEX Substitution Pattern
------------------------
0000 : 0 1000 : 8
0001 : 1 1001 : 9
0010 : 2 1010 : A
0011 : 3 1011 : B
0100 : 4 1100 : C
0101 : 5 1101 : D
0110 : 6 1110 : E
0111 : 7 1111 : F
However, you must be able to deal with hex numbers directly also.
1234_{16} = 4660_{10}

The following table shows how you can express a number, in four different bases: base 2, base 8, base 10 and base 16.

unsigned binary (base 2) | hex (base 16) | decimal (base 10) | octal (base 8) |

0 | 0 | 0 | 0 |

1 | 1 | 1 | 1 |

10 (2^{1} ) |
2 | 2 | 2 |

11 | 3 | 3 | 3 |

100 (2^{2} ) |
4 | 4 | 4 |

101 | 5 | 5 | 5 |

110 | 6 | 6 | 6 |

111 | 7 | 7 | 7 |

1000 (2^{3} ) |
8 | 8 | |

1001 | 9 | 9 | |

1010 | a | 10 (10^{1} ) | |

1011 | b | 11 | |

1100 | c | 12 | |

1101 | d | 13 | |

1110 | e | 14 | |

1111 | f | 15 | |

10000 (2^{4} ) |
10 (16^{1} ) |
16 | |

. . . | . . . | . . . | |

11111 | 1f | 31 | |

100000 (2^{5} ) |
20 | 32 | |

. . . | . . . | . . . | |

111111 | 3f | 63 | |

1000000 (2^{6} ) |
40 | 64 | |

. . . | . . . | . . . | |

1100011 | 63 | 99 | |

1100100 | 64 | 100 (10^{2} ) | |

. . . | . . . | . . . | |

1111111 | 7f | 127 | |

10000000 (2^{7} ) |
80 | 128 | |

. . . | . . . | . . . | |

11111111 | ff | 255 | |

100000000 (2^{8} ) |
100 (16^{2} ) |
256 | |

binary | hex | decimal |

NOTE:

Powers of 2 are: 2; 4; 8; 16; 32; 64; 128; 256; 512; 1,024; 2,048; 4,096; 8,192; 16,384; 32,768; 65,536 ...

Powers of 16 are: 16; 256; 4,096; 65,536 ...

Powers of 10 are: 10; 100; 1,000; 10,000 ...

.. Martian Fingers?
====================
A person lands on Mars and looks in a building that she finds.
It appears to be a school. The teacher has the following on the board:
6 + 4 = 12 10 x 10 = 100 13 + 6 = 21
So, how many fingers do Martians have?
.. Binary Barbeque?
===================
We have 12 (base ____) hotdogs that will match perfectly with our
package of 18 (base 10) buns.
We have a baker's dozen hamburger rolls and 10 (base ____) patties
which will match up perfectly.
We invited _____ people (base 7) meaning everyone will have one (base 3)
sandwich of some sort.
It was supposed to last 11 hours (base ____) which is like
going to 4 MWF classes!
This is the last of these 101 (base ____) statements about my BB.