Android examples for java.lang:Hex
is Hex Char
public class Main{ /**//from w w w. j a v a 2s .c om * Return true if the string is HexChars(1234567890abcdefABCDEF). * */ public static byte isHexChar(char ch) { if ('a' <= ch && ch <= 'f') return (byte) (ch - 'a' + 10); if ('A' <= ch && ch <= 'F') return (byte) (ch - 'A' + 10); if ('0' <= ch && ch <= '9') return (byte) (ch - '0'); return -1; } /** * Method Check String * * @param The string to be format. * * @param checkSpaceFlag=false: skip the space. * */ public static boolean isHexChar(String hexString, boolean checkSpaceFlag) { if (null == hexString || 0 == hexString.length()) return false; int hexLen = hexString.length(); int hexCharCount = 0; char ch; for (int i = 0; i < hexLen; i++) { ch = hexString.charAt(i); if (ch == ' ') { if (checkSpaceFlag) return false; } else { if (isHexChar(ch) < 0) return false; else hexCharCount++; } } if (hexCharCount % 2 != 0) return false; return true; } /** * Method Check String * * @param The string to be format. * */ public static boolean isHexChar(String hexString) { return isHexChar(hexString, true); } }