Octal

The octal system, while less common than binary or hexadecimal in general programming, plays a crucial role in specific areas like Unix file permissions. It uses the number 8 as its base to denote the numbers. Also, it remains important in specific areas, such as setting file permissions in Unix/Linux systems (e.g., chmod 755).

The numbers in the octal system are from 0 to 7, and the base is 8 (like binary, where the base is 2). We can convert octal numbers to decimal by using powers of 8, just like we use powers of 2 to convert binary numbers into decimal numbers.

Before we proceed to the examples, let us first revise the concept of data storage (just to refresh the memory):

UnitAbbreviationStandardSize (Bytes)
BitbBinary1/8
ByteBBinary1
KilobytekBDecimal1,000
KibibyteKiBBinary1,024
MegabyteMBDecimal1,000,000
MebibyteMiBBinary1,048,576
GigabyteGBDecimal1,000,000,000
GibibyteGiBBinary1,073,741,824

Now, we will see how to convert octal numbers into decimal numbers (the numbers that we use on a regular basis):
Before that, gain familiarity with the power tower of 8.

Example 1.1: Convert  {(345)_8} into a decimal number.

  1.  \text {Just like binary system, we will convert the number by using powers of 8 from right to the left.}
  2.  {(5 \times {8^0})+(4 \times {8^1})+(3 \times {8^2})}
  3.  {= (5 \times 1)+(4 \times 8)+(3 \times 64)}
  4.  {= 5+32+192}
  5.  {= (229)_{10}}

Example 1.2: Convert  {(3245)_8} into a decimal number.

  1.  {(5 \times {8^0})+(4 \times {8^1})+(2 \times {8^2})+(3 \times {8^3})}
  2.  {= (5 \times 1)+(4 \times 8)+(2 \times 64)+(3 \times 512)}
  3.  {= 5+32+128+1536}
  4.  {= (1701)_{10}}

Just like we saw how to convert octal numbers into decimal numbers, we will now understand how to convert decimal numbers into octal numbers by taking some examples.

Example 2.1: Convert  {(3425)_{10}} into an octal number.

  1. Divide 3425 by 8.
  2. Record the remainder (it will be between 0 and 7, including both).
  3. Take the quotient (the result of the division) and divide it by 8 again.
  4. Repeat until the quotient is 0.
StepDivisionQuotientRemainder
13425 ÷ 84281
2428 ÷ 8534
353 ÷ 865
46 ÷ 806

Now, read the remainders from the bottom to the top (from the last remainder to the first).
Bottom to top: $$ {(3425)_{10} = (6541)_8} $$

Example 2.2: Convert  {(1000)_{10}} into an octal number.

  1. Divide 1000 by 8.
  2. Record the remainder (it will be between 0 and 7, including both).
  3. Take the quotient (the result of the division) and divide it by 8 again.
  4. Repeat until the quotient is 0.
StepDivisionQuotientRemainder
11000 ÷ 81250
2125 ÷ 8155
315 ÷ 817
41 ÷ 801

Now, read the remainders from the bottom to the top (from the last remainder to the first).
Bottom to top: $$ {(1000)_{10} = (1750)_8} $$

Here it is. The basic process is to understand the octal number system. Practice it, Keep learning, stay curious, and All the Best!


Discover more from universeunlocks.in

Subscribe to get the latest posts sent to your email.

Leave a Reply