<p>A number with n digits can be represented this way:</p>
<pre><code> db^(n-1) + db^(n-2) + … + db^3 + db^2 + db^1 + db^0
</code></pre>
<p>where:
b is the base value
d is the digit value (ranges from 0 to (b-1))
* is multiplication sign
^ is the exponent sign</p>
<p>Notes: The exponent value increases from right to left. The leftmost digit is the most significant digit.</p>
<p>In the decimal system b = 10, d ranges from 0 to (10-1) or 0 to 9. This means in the decimal system, a digit value can be only 0,1,2,3,4,5,6,7,8,9</p>
<pre><code>9876543 = 910^6 + 810^5 + 710^4 + 610^3 + 510^2 + 410^1 + 310^0
= 91000000 + 8100000 + 710000 + 61000 + 5100 + 410 + 31
= 9000000 + 800000 + 70000 + 6000 + 500 + 40 + 3
= 9876543 (decimal, off course)
</code></pre>
<p>In the binary system b = 2, d ranges from 0 to (2-1) or 0 to 1. This means in the binary system, a digit value can be only 0 or 1.</p>
<pre><code>11111111= 12^7 + 12^6 + 12^5 + 12^4 + 12^3 + 12^2 + 12^1 + 12^0
= 1128 + 164 + 132 + 116 + 18 + 14 + 12 + 11
= 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1
= 255 (decimal)
10000000= 12^7 + 02^6 + 02^5 + 02^4 + 02^3 + 02^2 + 02^1 + 02^0
= 1128 + 064 + 032 + 016 + 08 + 04 + 02 + 01
= 128 + 0 + 0 + 0 + 0 + 0 + 0 + 0
= 128 (decimal)
</code></pre>
<p>In the hexadecimal system b = 16, d ranges from 0 to (16-1) or 0 to 15.
This means in the hexadecimal system, a digit value can be only 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
To simplify thing, people use A for 10, B for 11, C for 12, D for 13, E for 14, and F for 15</p>
<pre><code>FFFF = F16^3 + F16^2 + F16^1 + F16^0
= 1516^3 + 1516^2 + 1516 + 151
= 154096 + 15256 + 15*16 + 15
= 61440 + 3840 + 240 + 15
= 65535 (decimal)
FE0A = F16^3 + E16^2 + 016^1 + A16^0
= 1516^3 + 1416^2 + 016 + 101
= 154096 + 14256 + 0*16 + 10
= 61440 + 3584 + 0 + 10
= 65034 (decimal)
</code></pre>
<p>It’s very easy to convert from binary to hex. To convert from binary to hex, separate the binary digits into groups of 4 digits from right to left.
Then convert the 4-digit group into a decimal number. Then convert the decimal number into hex.</p>
<p>Ex: 11111111 (binary) = 1111,1111 (2 groups of 4 digits)
= 15 ,15 (2 decimal numbers)
= F ,F
= FF (hex)</p>
<pre><code> 1110100111 (binary) = 11,1010,0111 (3 groups of 4 digits)
= 3, 10, 7 (3 decimal numbers)
= 3, A, 7
= 3A7 (hex)
</code></pre>
<p>Similarly, to convert a hex number to binary, expand each hex digit into a 4 binary digit group.
Add zeros to left of the group if the expansion does not result in 4 binary digits.</p>
<pre><code>3A4E = 11, 1010, 100, 1110
= 0011, 1010, 0100, 1110 (2 zerors are added to the first group, 1 zero is added to the third group)
= 0011101001001110 (binary)
</code></pre>