package com.thealgorithms.conversions; /** * A utility class to convert an octal (base-8) number into its binary (base-2) representation. * *
This class provides methods to: *
An octal number is converted to binary by converting each octal digit to its 3-bit binary equivalent. * The result is a long representing the full binary equivalent of the octal number.
* ** long binary = OctalToBinary.convertOctalToBinary(52); // Output: 101010 (52 in octal is 101010 in binary) ** * @author Bama Charan Chhandogi * @see Octal Number System * @see Binary Number System */ public final class OctalToBinary { private OctalToBinary() { } /** * Converts an octal number to its binary representation. * *
Each octal digit is individually converted to its 3-bit binary equivalent, and the binary * digits are concatenated to form the final binary number.
* * @param octalNumber the octal number to convert (non-negative integer) * @return the binary equivalent as a long */ public static long convertOctalToBinary(int octalNumber) { long binaryNumber = 0; int digitPosition = 1; while (octalNumber != 0) { int octalDigit = octalNumber % 10; long binaryDigit = convertOctalDigitToBinary(octalDigit); binaryNumber += binaryDigit * digitPosition; octalNumber /= 10; digitPosition *= 1000; } return binaryNumber; } /** * Converts a single octal digit (0-7) to its binary equivalent. * *For example: *