 <p>It sounds like you're not trying to do huffman coding yet, just turn "binary" <code>String</code>s of <code>0</code> or <code>1</code> into Java integer types. Try this:</p> <pre><code>public static long decode(String textbytes) { long result=0; for(char ch : textbytes.toCharArray()) { result = result &lt;&lt; 1; if(ch == '1') result = result + 1; } return result; } </code></pre> <p>This method decodes bit strings into Java <code>long</code>s. There's no need to worry about breaking into chunks of 8 (unless this is homework, and that's part of the assignment). In particular, it handles the example you gave properly ("11010001" => 209).</p> <p>The approach is pretty simple:</p> <ol> <li>Start with <code>result = 0</code></li> <li>For each character in the input string, shift <code>result</code> 1 bit to the left to "make room" for the bit represented by the current character. Afterwards, add <code>1</code> to result if the current character represents a <code>1</code> bit.</li> </ol> <p>Also, the code assumes you get no bit strings longer than 64 bits, which you may want to check for robustness.</p>