Java tutorial
//package com.java2s; import java.io.IOException; public class Main { public static byte[] decodeQ(byte[] bytes) throws IOException { int len = bytes.length; int length = 0; for (int i = 0; i < len; i++) { byte b = bytes[i]; if (b == '=') { i++; if (i == len) break; b = bytes[i]; if (b == '\r' || b == '\n') { b = bytes[++i]; if (b != '\n') { i--; } continue; } int result = -Character.digit(b, 16); result *= 16; result -= Character.digit(bytes[++i], 16); bytes[length++] = (byte) -result; } else { bytes[length++] = b; } } byte[] result = new byte[length]; System.arraycopy(bytes, 0, result, 0, length); return result; } public static String decodeQ(String str, String charsetName) throws IOException { byte[] bs = str.getBytes(); int len = bs.length; int length = 0; for (int i = 0; i < len; i++) { byte b = bs[i]; if (b == '=') { i++; if (i == len) break; b = bs[i]; if (b == '\r' || b == '\n') { b = bs[++i]; if (b != '\n') { i--; } continue; } int result = -Character.digit(b, 16); result *= 16; result -= Character.digit(bs[++i], 16); bs[length++] = (byte) -result; } else { bs[length++] = b; } } return new String(bs, 0, length, charsetName); } }