General Discussion > Mathematics and Statistics

Octal system (base 8)

(1/2) > >>

Vawmataw:
How to convert a number in base 10 to a number in base 8?

Tìtstewan:
From Wikipedia: :)

For example, to convert 12510 to octal:

125 / 82 = 1
125 − 82 × 1 = 61
61 / 81 = 7
61 − 81 × 7 = 5
5 / 80 = 5

Therefore, 12510 = 1758.

Another example:

900 / 83 = 1
900 − 83 × 1 = 388
388 / 82 = 6
388 − 82 × 6 = 4
4 / 81 = 0
4 − 81 × 0 = 4
4 / 80 = 4

Therefore, 90010 = 16048.

Vawmataw:

--- Quote from: Tìtstewan on September 24, 2012, 04:34:57 pm ---From Wikipedia: :)

For example, to convert 12510 to octal:

125 / 82 = 1
125 − 82 × 1 = 61
61 / 81 = 7
61 − 81 × 7 = 5
5 / 80 = 5

Therefore, 12510 = 1758.

Another example:

900 / 83 = 1
900 − 83 × 1 = 388
388 / 82 = 6
388 − 82 × 6 = 4
4 / 81 = 0
4 − 81 × 0 = 4
4 / 80 = 4

Therefore, 90010 = 16048.

--- End quote ---
You don't help me, because I searched that in Wikipedia, and it's not clear.

Tìtstewan:
Sorry I would write an another method:
I was too slow ...
Another exampel:
12210
122 : 8 = 15 R - 2 at 3rd
15 : 8 =  1 R - 7 at 2nd
1 : 8 =  0 R - 1 at 1st

1728

You have to divide with 8.

Blue Elf:
The first example is a little confusing, as there's something missing:

125 / 8^2 = 1
125 − 8^2 × 1 = 61
61 / 8^1 = 7
61 − 8^1 × 7 = 5
5 / 8^0 = 5

Power mark is important. By words:
- find the highest power of 8 smaller than number you are converting (64 = 8^2 in our case)
- perform division and remember remainder: 125 / 64 = 1, remainder = 61
- repeat these steps, while decreasing number in red, until you get remainder 0:
61 / 8^1 = 61 / 8 = 7, remainder = 5
5 / 8^0 = 5 / 1 = 5, remainder = 0
Now write all result in sequence:
125(10) = 175(8 )