/** * Convert integer to four letter hex code. Ignores negative values. * * @param _in * @return corresponding string as hex */ public static String toHex4String(int _in) { return toHex2String(_in / 256) + toHex2String(_in % 256); }
/** * Convert Color information to string. Do not store alpha value. * * @param _in * @return color as string */ public static String toString(Color _in) { return "#" + MCast.toHex2String(_in.getRed()) + MCast.toHex2String(_in.getGreen()) + MCast.toHex2String(_in.getBlue()); }
public static String toReadableChar(char b) { if (b == 13) return "<BR>"; if (b == 10) return "<CR>"; if (b == '\t') return "<TAB>"; if (b < ' ' ) return "<" + MCast.toHex2String(b).toUpperCase() + ">"; return new String(new char[] {b}); }
public static String encodeURIComponent(String _in) { if (_in == null) return ""; StringBuilder out = new StringBuilder(); for (int i = 0; i < _in.length(); i++) { char c = _in.charAt(i); if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '-' || c == '.' || c == '!' || c == '~' || c == '*' || c == '\'' || c == '(' || c == ')') { out.append(c); } else { out.append('%' + MCast.toHex2String(c)); } } return out.toString(); }
public static String toHexDump(byte[] bc, int lineSize) { if (bc == null) return ""; StringBuilder out = new StringBuilder(); int off = 0; while(off < bc.length) { for (int i = 0; i < lineSize; i++) { if (off+i < bc.length) out.append(MCast.toHex2String(bc[off + i]).toUpperCase() ); else out.append(" "); if (i % 4 == 3) out.append(" "); } out.append(" "); for (int i = 0; i < lineSize; i++) { if (off+i < bc.length) out.append(MCast.toReadableChar((char)bc[off + i]) ); } out.append('\n'); off = off + lineSize; } return out.toString(); }
result.print("X'"); for (byte b : bytes) { result.print(MCast.toHex2String(b));