diff --git a/src/main/java/com/thealgorithms/conversions/OctalToBinary.java b/src/main/java/com/thealgorithms/conversions/OctalToBinary.java index 6b01c2f65cfe..a66db97633b4 100644 --- a/src/main/java/com/thealgorithms/conversions/OctalToBinary.java +++ b/src/main/java/com/thealgorithms/conversions/OctalToBinary.java @@ -1,14 +1,40 @@ package com.thealgorithms.conversions; /** - * Converts any Octal Number to a Binary Number + * 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; @@ -20,12 +46,25 @@ public static long convertOctalToBinary(int octalNumber) { binaryNumber += binaryDigit * digitPosition; octalNumber /= 10; - digitPosition *= 1000; // Move to the next group of 3 binary digits + digitPosition *= 1000; } return binaryNumber; } + /** + * Converts a single octal digit (0-7) to its binary equivalent. + * + *For example: + *