Computer Science, asked by guuuooo, 1 year ago

design an algorithm and draw a flowchart to convert a decimal number into an octal number

Answers

Answered by SatyaM711
0
Algorithm for converting a decimal number to an octal:

Suppose the decimal number is (569)_10. (From now on, ()_x denotes the base of the preceding number inside parentheses)

To obtain the octal (or any other number system) equivalent to this number, there's the need for using two operators in conjunction: the floor division and the modulo

How these work:

1. The "floor division": Suppose there are two numbers x and y,
now if x // y = k ('//' symbol denotes the "floor division" operation),
then x = ky + m where k, m have integral values.

2. The "modulo": Again, considering arbitrarily two numbers x and y, if x % y = k (the "modulo" operation is denoted by '%' symbol), then x = ny + k where n, k have integral values.

Now, to find the octal number of the given decimal, we need to operate on the decimal number the floor division as well as the modulo simultaneously (with the second number in the operation being 8 since octal). The quotient obtained through floor division again needs to be subjected to the dual operation and this step needs to be iterated till the quotient is less than the divisor and the process ends.

Working out of the example: conversion of (569)_10 to (?)_8

Step 1: 569 // 8 = 71 and 569 % 8 = 1

Step 2: 71 // 8 = 8 and 71 % 8 = 7

Step 3: 8 // 8 = 1 and 8 % 8 = 0

Step 4: 1 // 8 = 0 and 1 % 8 = 1
Hence, the octal equivalent is ( modulo(Step 4), modulo(Step 3), modulo(Step 2), modulo(Step 1) )_8 = (1071)_8 i.e.

(469)_10 = (1071)_8

Similar questions