Hex and Octal
Objectives
We would like to :- Understand the basics of the hexadecimal and octal number systems.
- Understand why these systems are used
- Understand how to convert from/to binary.
Notes
- A 32 bit binary number might look like this 101111011110010011111001011001112
- What are the chances of you copying this number WITHOUT making a mistake?
- There are two number systems that make this easier
- Octal or base 8
- Hexadecimal (hex) or base 16.
- Notice these are both powers of 2.
- Octal: base 8
- Digits = {0,1,2,3,4,5,6,7}.
- Base = 8
- Notice that all of these digits can be represented in 3 bits in binary
0 0002 1 0012 2 0102 3 0112 4 1002 5 1012 6 1102 7 1112
- SO to represent a binary number in octal,
- Break the binary number into 3 bit substrings starting on the right.
- Pad with at most two zeros on the left.
- Write down the associated octal digit for each substring.
- Example:
101111011110010011111001011001112 becomes 10 111 101 111 001 001 111 100 101 100 1112 becomes 010 111 101 111 001 001 111 100 101 100 1112 becomes 010 111 101 111 001 001 111 100 101 100 1112 2 7 5 7 1 1 7 4 5 4 7 8 becomes 275711745478
- Hexadecimal, base 16
- We run out of decimal digits, so we use a,b,c,d,e,f or A,B,C,D,E,F
- Digits = { 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
0 00002 8 10002 1 00012 9 10012 2 00102 A 10102 3 00112 B 10112 4 01002 C 11002 5 01012 D 11012 6 01102 E 11102 7 01112 F 11112
- You should be able to convert between base 2 and base 16 for the first 16 values very rapidly.
- SO to represent a binary number in hex,
- Break the binary number into 4 bit substrings starting on the right.
- Pad with at most three zeros on the left.
- Write down the associated octal digit for each substring.
- Example:
101111011110010011111001011001112 1011 1101 1110 0100 1111 1001 0110 01112 B D E 4 F 9 6 7 8 BDE4F9678
- Conversion to other bases
- I would go to either binary or decimal depending on the task.
- Expectations:
- I expect that you are able to represent numbers in decimal, hex, octal and binary.
- I expect that you are able to convert between decimal, hex, octal and binary.