Android Utililty Methods Hex String Create

List of utility methods to do Hex String Create

Description

The list of methods to do Hex String Create are organized into topic(s).

Method

inthexCharToInt(char c)
hex Char To Int
if (c >= '0' && c <= '9')
    return (c - '0');
if (c >= 'A' && c <= 'F')
    return (c - 'A' + 10);
if (c >= 'a' && c <= 'f')
    return (c - 'a' + 10);
throw new RuntimeException("invalid hex char '" + c + "'");
voidhexDecode(String str, byte[] ba, int len)
hex Decode
char[] cp = str.toCharArray();
byte nbl = 0;
int i = 0;
int icp = 0;
int iba = 0;
for (; i < len; i++, icp++) {
    if (cp[icp] >= '0' && cp[icp] <= '9')
        nbl = (byte) (cp[icp] - '0');
...
StringhexEncode(byte[] aInput)
hex Encode
StringBuilder result = new StringBuilder();
char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        'a', 'b', 'c', 'd', 'e', 'f' };
for (int idx = 0; idx < aInput.length; ++idx) {
    byte b = aInput[idx];
    result.append(digits[(b & 0xf0) >> 4]);
    result.append(digits[b & 0x0f]);
return result.toString();
Stringhexify(byte bytes[])
hexify
char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
        '9', 'a', 'b', 'c', 'd', 'e', 'f' };
StringBuffer buf = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; ++i) {
    buf.append(hexDigits[(bytes[i] & 0xf0) >> 4]);
    buf.append(hexDigits[bytes[i] & 0x0f]);
return buf.toString();
...
StringtoHex(String str)
to Hex
String hexString = "0123456789ABCDEF";
byte[] bytes = str.getBytes();
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (byte aByte : bytes) {
    char temp1 = hexString.charAt((aByte & 0xf0) >> 4);
    char temp2 = hexString.charAt(aByte & 0x0f);
    if (!(temp1 == '0' && temp2 == '0')) {
        sb.append(temp1);
...
StringtoHex(String txt)
to Hex
return toHex(txt.getBytes());
StringtoHex(byte b)
Encodes a single byte to hex symbols.
StringBuilder sb = new StringBuilder();
appendByteAsHex(sb, b);
return sb.toString();
StringtoHex(byte input[])
to Hex
if (input == null)
    return null;
StringBuffer output = new StringBuffer(input.length * 2);
for (int i = 0; i < input.length; i++) {
    int current = input[i] & 0xff;
    if (current < 16)
        output.append("0");
    output.append(Integer.toString(current, 16));
...
StringtoHex(byte[] bytes)
to Hex
BigInteger bi = new BigInteger(1, bytes);
return String.format("%0" + (bytes.length << 1) + "X", bi);
StringtoHex(byte[] data)
to Hex
if (data == null || data.length == 0)
    return null;
StringBuilder stringBuilder = new StringBuilder(data.length * 2);
Formatter formatter = null;
try {
    formatter = new Formatter(stringBuilder);
    for (byte b : data) {
        formatter.format("%02x", b);
...