Here you can find the source of toBinFromOct(final String octSymbols)
Parameter | Description |
---|---|
octSymbols | The oct symbol string to transform |
public static String toBinFromOct(final String octSymbols)
//package com.java2s; //License from project: Open Source License public class Main { public final static int BITS_PER_OCT_DIGIT = 3; /**// ww w .ja va 2 s . c om * Transform a string of octal symbols to a string of binary symbols * * @param octSymbols * The oct symbol string to transform * @return The binary string that corresponds to the input octal string */ public static String toBinFromOct(final String octSymbols) { StringBuilder bits = new StringBuilder(octSymbols.length() * BITS_PER_OCT_DIGIT); for (int i = 0; i < octSymbols.length(); i++) { bits.append(toBinFromOctChar(octSymbols.charAt(i))); } return (bits.toString()); } public static String toBinFromOctChar(final char oct) { switch (oct) { case '0': return ("000"); case '1': return ("001"); case '2': return ("010"); case '3': return ("011"); case '4': return ("100"); case '5': return ("101"); case '6': return ("110"); case '7': return ("111"); default: throw new IllegalArgumentException( "The input character \'" + oct + "\'is not a valid octal character."); } } }