#P6353. Binary to Octal Conversion
Binary to Octal Conversion
Binary to Octal Conversion
Given a binary number as a string, convert it into an octal number using the following steps:
- If the number of digits is not divisible by 3, pad the number on the left with zeros \(0\) until the length becomes a multiple of 3.
- Divide the padded binary string into groups of 3 digits.
- Replace each group with its corresponding octal digit. For example, the binary group
101
converts to \(5\) since \(1\times2^2+0\times2^1+1\times2^0=5\).
Output the resulting octal number as a string.
inputFormat
The input consists of a single line containing a binary number (a string of characters '0' and '1').
outputFormat
Output the octal representation of the given binary number as described.
sample
101
5