public byte[] fromBitString(String str) {
        // no need for performance or memory tuning ...
        int strLen = str.length();
        int bLen = str.length() / 8;
        if (strLen % 8 != 0)
            bLen++;

        byte[] bytes = new byte[bLen];
        int charI = 0;
        for (int b = bLen - 1; b >= 0; b--) {
            byte res = 0;
            for (int i = 0; i < 8; i++) {
                res <<= 1;
                if (charI < strLen && str.charAt(charI) != '0')
                    res |= 1;

                charI++;
            }
            bytes[b] = res;
        }
        return bytes;
    }
@Test
    public void testFromBitString() {
        String str = "001110110";
        assertEquals(str + "0000000", bitUtil.toBitString(bitUtil.fromBitString(str)));

        str = "01011110010111000000111111000111";
        assertEquals(str, bitUtil.toBitString(bitUtil.fromBitString(str)));

        str = "0101111001011100000011111100011";
        assertEquals(str + "0", bitUtil.toBitString(bitUtil.fromBitString(str)));
    }