Octal numbers are those having 8 as its base. Octal numbers have a set of only 8 digits, -not including "8". They are 0, 1, 2, 3, 4, 5, 6 and 7. Binary numbers are those having 2 as its base. They have only 2 digits, 0 and 1. We can also refer to each digit as being turned off or on. Take a look at this table:
Decimal | Binary | Octal ------------------------- 0 | 00000 | 0 1 | 00001 | 1 2 | 00010 | 2 3 | 00011 | 3 4 | 00100 | 4 5 | 00101 | 5 6 | 00110 | 6 7 | 00111 | 7 8 | 01000 | 10 9 | 01001 | 11 10 | 01010 | 12 11 | 01011 | 13 12 | 01100 | 14
The first digit in octal, matches the 3 digits of its binary equivalent from left to right, the next one the next 3 remaining binary digits and so on.
First of all, we will draw an example grid to have at hand in order to convert from binary to decimal, assuming that the LSB (Less Significant Bit) is at the right side and that we will work with byte-length binary numbers:
2^8 | 2^6 | 2^5 | 2^4 | 2^3 | 2^2 | 2^1 | 2^0 | Sum ----------------------------------------------------- 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | 256 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 81
In this example, we convert the binary number 1010000 to decimal. To get decimal numbers from binary ones, place the binary number within the lower row of this grid and sum all the decimal numbers above digits 1. Now that you understand how easy is to convert binary numbers to/from decimals, let's get back to octals.
Example: Get the octal number for the decimal 243
When translating decimals to binary numbers, we should start "turning on"
the bit below the nearest decimal to the number we want to convert.
In this case, it is 128. Then we see whether adding the next right decimal of the
grid doesn't exceed our original number (243).
So, we have 128 + 64 = 192. We keep repeating the process confidently
while our sum keeps producing a result below our decimal number (243).
Now we have 128 + 64 + 32 + 16 = 240
If we add 8, our result would be 248, greater than 243, so we just
leave this bit "turned off" (0) and try the next one, going always
from left to right.
This way, we end up turning on the bit below 2 and 1, so we finally
have our desired binary number:
11110011 2^8 | 2^6 | 2^5 | 2^4 | 2^3 | 2^2 | 2^1 | 2^0 | Sum ----------------------------------------------------- 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | 256 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 243
Now getting our octal number is the easiest part. We split our binary number into groups of 3, from right to left:
11110011 = [11] [110] [011]
Now we just convert our splited parts back to decimal and write down each resulting digit below the corresponding binary part.
11110011 = [11] [110] [011] 3 6 3 = Octal value: 363
Although this is a very good practice from the binary point of view, there is a quicker method for conversion. The algorithm works as follows:
Example: 243 / 8 = 30, r = 3 30 / 8 = 3, r = 6 3 / 8 = 0, r = 3 Octal number: 363 This example is a bit ambigous as the number ends and begins with 3, so let's convert 494 to octal: 494 / 8 = 61, r = 6 61 / 8 = 7, r = 5 7 / 8 = 0, r = 7 Octal number: 756
Example: Get the decimal number for the octal 755
We take each digit and convert it to a binary number, from right
to left just to avoid making mistakes.
[111] [101] [101] 7 5 5
Now we place the three binary parts in the same order into the grid and
perform a basic binary/decimal conversion. We place the binary number
making it match the right side. As we have 9 digits, we would append the
next power for the 9th bit (2^9 = 256) to the left column of the grid.
So, 755 is 111101101 = Decimal number: 493
Of course, we can use en easier algorithm to avoid this long but
demostrative process:
So that would be: 8 * 7 + 5 = 61 8 * 61 + 5 = 493 Decimal number: 493 But let's just take a larger octal, 32565 for example: 8 * 3 + 2 = 26 8 * 26 + 5 = 213 8 * 213 + 6 = 1710 8 * 1710 + 5 = 13685 Decimal number: 13685
Depending of the computer arquitecture, the LSB (Less Significant Bit) may be on the left or right side. For these examples, we just assume that it is on the right side. It's harder but it will help you to understand old litearature where the right LSB is the standard.
Hexadecimal numbers are in base 16. That means that each hexadecimal digit has 16 units. So how do we represent numbers, 10, 11, 12, 13, 14, and 15? We use the letters A, B, C, D, E and F respectively. We won't cover decimal/binary conversion here at is it alrady explained at the [Octal and Binary Numbers] section. But we will also explain hexadecimal numbers around binary numbers, so here it is basic reference table.
Decimal | Binary | Hexa ------------------------- 0 | 00000 | 0 1 | 00001 | 1 2 | 00010 | 2 3 | 00011 | 3 4 | 00100 | 4 5 | 00101 | 5 6 | 00110 | 6 7 | 00111 | 7 8 | 01000 | 8 9 | 01001 | 9 10 | 01010 | A 11 | 01011 | B 12 | 01100 | C 13 | 01101 | D 14 | 01110 | E 15 | 01111 | F 16 | 10000 | 10 17 | 10001 | 11 Hexadecimal numbers are even easier to work with as each digit is represented by 4 bits. (a nibble or half a byte).
Example: Get the hex number for the decimal 253 We translate the number to binary, so we have: 253 = 11111101 Now we split it in groups of four bits: [1111] [1101] We get the decimal value for each part and write it down remembering that 10, 11, 12, 13, 14, and 15 are represented by digits A, B, C, D, E and F respectively: [1111] [1101] F D Hexadecimal number: FD
By using the same octal alogirthm, you can also get hexadecimal numbers out of decimals without sweat:
253 / 16 = 15, r = 13 (D) 15 / 16 = 0, r = 16 (F) Hexadecimal number: FD
Example: What is the decimal value of F36A? By using the binary approach: Get the binary value for each hexadecimal digit and convert the resulting big binary number to decimal: [1111] [0011] [0110] [1010] = 1111001101101010 = 62314 F 3 6 A Decimal number: 62314
By using the multiplication alogirthm:
So that would be: 16 * 15(F) + 3 = 243 16 * 243 + 6 = 3894 16 * 3894 + 10 (A) = 62314 Decimal number: 62314
Scientific notation was conceived to easily represent numbers that are
either too large or too small.
For example:
A number in the scientific notation contains 3 elements: 1.23E-6 [ 1.23 ] [E] [-6] A B C A) The multiplicand: should be lower than 10 and greater than 0 B) The scientific notation symbol. It is "EXP" sometimes. The exponent is always 10. Sometimes, it is written just like 1.23 x 10^-6 C) The index of the exponent, which may be positive (+) or negative (-)
Example #1: Convert 200,000,000,000 to the scientific notation: 1) The multiplicand should be lower than 10, so we take the first number, which is 2. 2 2) We count the number of zeroes from the number we choosed (2). There are 11 of them. 3) Now we have the elements needed to conform our scientific expression: Result: 2E+11 Example #2: Convert 0.005,432 to the scientific notation: 1) We take 5.432 as the multiplicand as it is < 10 and > 1. 5.432 2) There are 3 zeroes to the left. 4) As the zeroes are to the left, we use a negative index: Result: 5.432E-3 - Conversion from the scientific notation to plain decimals Example #1: What is the value of 3.434E+5? 1) Write multiplicand. 3.434 2) Move the point as many times as indicated by the index to the right (it is positive). 3434__. 3) Fill the blank spaces with zeroes (you left 2 of them). 343400 Result: 343400 Example #1: What is the value of 9.3E-9? 1) Write multiplicand. 9.3 2) Move the point as many times as indicated by the index to the left (it is negative). .________93 3) Fill the blank spaces with zeroes (you left 8 of them). .0000000093 Result: 0.0000000093 Of course you can place a zero (0) each time you move the dot to the left or to the right, making the conversion in one shot that way.
| © Ernesto Garbarino | Top |