Binary - Base 2
Numbering System Contains two symbols:
0 -> off, false, no power
1 -> on, true, power
*Basic Numbering System Used By ALL Computing Devices*
Cheap, Easy to Represent in Computing!
Converting Binary Number to Decimal
(from right to left)
0111 converts to decimal:
2 raised to 0 power is on: 1
2 raised to 1st power is on: (2 X 1) = 2
2 raised to 2nd power is on: (2 X 2) = 4
2 raised to 3rd power is off.
(add to get total) 1+2+4=7 in decimal
Converting Decimal Number to Binary
converting 72 to Binary
(a) take biggest multiple of power of 2 out
(b) for 72 biggest is 64 which is 2 raised to 6th power
(c) subtract the 64 from 72 which leaves 8 left
(d) go back to (a) using 8 -> 8 fits perfectly into
2 raised to 3rd power -- when you are at zero you are done
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
0 |
1 |
0 |
0 |
1 |
0 |
0 |
0 |
Additional Info
8 bits called a byte
4 bits called a nibble
64 bits or 8 bytes called a word
max decimal value that can fit into a byte is 255
(which is 2 raised to 8th power - 1)
Hexadecimal - Base 16
Numbering System Contains 16 symbols:
0 through 9 = numeric 0 to 9;
A=10; B=11; C=12; D=13; E=14; F=15;
A Shortcut Notation to Represent Binary Numbers
(especially long Binary Numbers)
Converting a Hex Number to Decimal
Steps:
- Get the last
digit of the hex number, call this digit the
currentDigit.
- Make a variable,
let's call it power. Set the value to 0.
- Multiply the
current digit with (16^power), store
the result.
- Increment
power by 1.
- Set the the
currentDigit to the previous digit of the
hex number.
- Repeat from step
3 until all digits have been multiplied.
- Sum the result
of step 3 to get the answer number.
Example 1
Convert the number
1128
HEXADECIMAL to DECIMAL
MULTIPLICATION |
RESULT |
NOTES |
8 x (16^0) |
8 |
Start from
the last digit of the number. In this
case, the number is 1128. The
last digit of that number is
8.
Note that the power of 0 of any number
is always 1
|
2 x (16^1) |
32 |
Process the
previous, which is
2.
Multiply that number with an increasing
power of 16. |
1 x (16^2) |
256 |
Process the
previous digit, which is
1, note
that 16^2 means 16 x 16 |
1 x (16^3) |
4096 |
Process the
previous digit, which is
1, note
that 16^3 means 16 x 16 x 16 |
|
|
Here, we
stop because there's no more digit to
process |
ANSWER |
4392 |
This number
comes from the sum of the
RESULTS
(8+32+256+4096)=4392 |
Once discerned,
notice that the above process is essentially
performing this calculation:
1x(16^3)
+ 1x(16^2) +
2x(16^1) +
8x(16^0)
When doing this by
hand, it is easier to start backward is because:
- Counting the
number of digits takes extra time, and you might
count wrongly.
- If you don't
remember what a particular value of a
power-of-16 is, it's easier to calculate it from
the previous power value. For instance, if you
don't remember what the value of 16^3 is, then
just multiply the value of 16^2 (which you'll
likely already have if you started backward)
with 16.
|
|
Converting a Decimal to Hex Number
Steps:
- Divide the
decimal number by 16. Treat the division as an
integer division.
- Write down the
remainder (in hexadecimal).
- Divide the
result again by 16. Treat the division as an
integer division.
- Repeat step 2
and 3 until result is 0.
- The hex value is
the digit sequence of the remainders from the
last to first.
Note: a remainder
in this topic refers to the left over value after
performing an integer division.
HEXADECIMAL |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
A |
B |
C |
D |
E |
F |
DECIMAL |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
Example 1
Convert the number
1128 DECIMAL to HEXADECIMAL
NOTES |
DIVISION |
RESULT |
REMAINDER (in HEXADECIMAL) |
Start by dividing the number by
16.
In this case, 1128 divided by 16
is 70.5. So the integer
division result is 70 (throw out
anything after the decimal
point).
The remainder is (70.5 - 70)
multiplied with 16; or (0.5
times 16), which is 8.
|
1128
/ 16 |
70 |
8 |
Then, divide the result again by
16
(the number 70 on the DIVISION
column comes from the previous
RESULT).
In this case, 70/16=4.375. So
the integer division result is 4
(throw out anything after the
decimal point)
The remainder is (0.375
multiplied with 16, which is 6.
|
70 /
16 |
4 |
6 |
Repeat. Note here that
4/16=0.25. So the integer
division result is 0.
The remainder is (0.25-0)
multiplied with 16, which is 4.
|
4 /
16 |
0 |
4 |
Stop
because the result is already 0
(0 divided by 16 will always be
0)
|
|
|
|
Well, here is the answer. These
numbers come from the REMAINDER
column values (read from bottom
to top) |
|
|
468 |
Side note:
You can get the remainder of a division
using the Modulus or %
operator. Ie: 1128%16=8. |
|
|
Converting a Hex Number to Binary Number
164 in Hex Convert to Binary
take each Hex Digit and convert equivalent four bit value;
for example 164:
1 represented in 4 bits is: 1000
6 represented in 4 bits is: 0110
4 represented in 4 bits is: 0010
answer is: 1000 0110 0010 in binary
Converting a Binary Number to Hex
take the binary number say:
1000 0110 0010 and segment in groups of four bits and apply Hex
Number for each four bits.
for example:
0001 0110 0100
0001 = 1
0110 = 6
0100 = 4
answer is 164 in Hex
Octal - Base 8
Numbering System Contains 8 symbols:
0 through 7 = numeric 0 to 7;
A Shortcut Notation to Represent Binary Numbers
(from right to left)
Converting an Octal Number to Decimal
Octal 45 to Decimal
5 is at the 8 to zero power
4 is at the 8 to 1st power
(5 X (8 to 0 power); which is the ones) =5
+
(4 x (8 to 1st power)) = 32
(5 + 32) = total of 37
Converting a Decimal Number to Octal
Decimal 45 to Octal
How many times does 8 go into 45; answer is 5 with a reminder of 5;
so (we have five, 8s in the 8 to 1st power position)
and (we have five, 8s in the 8 to 0 power position)
answer is 55 |