/*
Convert an array of little-endian words to a hex string.
500457
function binl2hex(binarray)
{
    var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
    var str = "";
    for (var i = 0; i < binarray.length * 4; i++) {
        str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) + hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF);
    }
    return str;
}
1047932
public static byte[] hexToBytes(char[] hex)
    {
        int length = hex.length / 2;
        byte[] raw = new byte[length];
        for (int i = 0; i < length; i++)
        {
            int high = Character.digit(hex[i * 2], 16);
            int low = Character.digit(hex[i * 2 + 1], 16);
            int value = (high << 4) | low;
            if (value > 127)
            {
                value -= 256;
            }
            raw[i] = (byte) value;
        }
        return raw;
    }
826844
public static String hex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for (int j = 0; j < bytes.length; j++) {
            int v = bytes[j] & 0xFF;
            hexChars[j * 2] = HEXES_SMALL[v >>> 4];
            hexChars[j * 2 + 1] = HEXES_SMALL[v & 0x0F];
        }
        return new String(hexChars);
    }
406486
private static String byteArrayToHexString(byte[] byteArray) {
		StringBuilder result = new StringBuilder();
		
		for (int i=0; i < byteArray.length; i++) {
			result.append(Integer.toString((byteArray[i] & 0xff) + 0x100, 16).substring(1));
		}
		
		return result.toString();
	}
822294
public static byte[] hexToBytes( String hex ) {
        int byteLen = hex.length() / 2;
        byte[] bytes = new byte[byteLen];

        for( int i = 0; i < hex.length() / 2; i++ ) {
            int i2 = 2 * i;
            if (i2 + 1 > hex.length())
                throw new IllegalArgumentException("Hex string has odd length");

            int nib1 = hexToInt(hex.charAt(i2));
            int nib0 = hexToInt(hex.charAt(i2 + 1));
            byte b = (byte) ((nib1 << 4) + (byte) nib0);
            bytes[i] = b;
        }
        return bytes;
    }
658251
private static String byte2hex(byte[] bytes) {
        char[] hexChars =
                {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b',
                        'c', 'd', 'e', 'f'};

        StringBuffer sb = new StringBuffer();
        for (byte b : bytes) {
            sb.append(hexChars[b >> 4 & 0xf]);
            sb.append(hexChars[b & 0xf]);
        }

        return new String(sb);
    }
68407
function b64toBA(s) {
  //piggyback on b64tohex for now, optimize later
  var h = b64tohex(s);
  var i;
  var a = new Array();
  for(i = 0; 2*i < h.length; ++i) {
    a[i] = parseInt(h.substring(2*i,2*i+2),16);
  }
  return a;
}
582859
function b64nltohex(s) {
    var b64 = s.replace(/[^0-9A-Za-z\/+=]*/g, '');
    var hex = b64tohex(b64);
    return hex;
}
281976
private static String convertToHex(byte[] data) {

        final StringBuffer buffer = new StringBuffer();

        for (int i = 0; i < data.length; i++) {

            int halfByte = (data[i] >>> 4) & 0x0F;
            int twoHalves = 0;

            do {

                if ((0 <= halfByte) && (halfByte <= 9)) {
                    buffer.append((char) ('0' + halfByte));
                } else {
                    buffer.append((char) ('a' + (halfByte - 10)));
                }

                halfByte = data[i] & 0x0F;

            } while(twoHalves++ < 1);
        }

        return buffer.toString();
    }
1056539
public static String toHexString( byte[] b ) {
        if ( null == b )
            return null;
        int len = b.length;
        byte[] hex = new byte[ len << 1 ];
        for ( int i = 0, j = 0; i < len; i++, j+=2 ) {
            hex[ j ] = (byte) ((b[ i ] & 0xF0) >> 4);
            hex[ j ] += 10 > hex[ j ] ? 48 : 87;
            hex[ j + 1 ] = (byte) (b[ i ] & 0x0F);
            hex[ j + 1 ] += 10 > hex[ j + 1 ] ? 48 : 87;
        }
        return new String( hex );
    }
1258615
function (utf16Str) {
            // Shortcut
            var utf16StrLength = utf16Str.length;

            // Convert
            var words = [];
            for (var i = 0; i < utf16StrLength; i++) {
                words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16));
            }

            return WordArray.create(words, utf16StrLength * 2);
        }
85799
public static String hexDump(byte[] array, int offset, int length) {
            if (length < 0) {
              throw new IllegalArgumentException("length: " + length);
            }
            if (length == 0) {
                return EMPTY_STRING;
            }
            int endIndex = offset + length;
            char[] buf = new char[length << 1];

            int srcIdx = offset;
            int dstIdx = 0;
            for (; srcIdx < endIndex; srcIdx ++, dstIdx += 2) {
                System.arraycopy(
                    HEXDUMP_TABLE, (array[srcIdx] & 0xFF) << 1,
                    buf, dstIdx, 2);
            }
            return new String(buf);
        }
327402
function bytesToHex(arr) {
    if (arr instanceof ArrayBuffer) {
        arr = new Uint8Array(arr);
    }
    var str = '';
    for (var i = 0; i < arr.length; i++) {
        var byte = arr[i].toString(16);
        if (byte.length === 1) {
            str += '0';
        }
        str += byte;
    }
    return str;
}
263682
public function littleEndian($hex)
    {
        $result = '';

        for ($x = strlen($hex) - 2; $x >= 0; $x = $x - 2) {
            $result .= substr($hex, $x, 2);
        }

        return $result;
    }
621767
public static String toHexString(byte in[]) {
		if(in == null || in.length <= 0) {
			return null;
		}

		int i = 0;
		byte ch = 0x00;
		String pseudo[] = {
				"0", "1", "2", "3",
				"4", "5", "6", "7",
				"8", "9", "A", "B",
				"C", "D", "E", "F"
		};

		StringBuffer out = new StringBuffer(in.length * 2);
		while(i < in.length) {
			ch = (byte)(in[i] & 0xF0);		// Strip off high nibble
			ch = (byte)(ch >>> 4);			// shift the bits down
			ch = (byte)(ch & 0x0F);			// must do this is high order bit is on!
			out.append(pseudo[(int)ch]);	// convert the nibble to a String Character
			ch = (byte)(in[i] & 0x0F);		// Strip off low nibble 
			out.append(pseudo[(int)ch]);	// convert the nibble to a String Character
			out.append(' ');
			i++;
		}

		return new String(out);
	}
1204498
function (mem) {
    var hexMem = this.hexConvert(mem).substr(2)
    var ret = []
    for (var k = 0; k < hexMem.length; k += 32) {
      var row = hexMem.substr(k, 32)
      ret.push(row)
    }
    return ret
  }
953114
function toUtf8(hex) {
  const bufferValue = new Buffer(padToEven(stripHexPrefix(hex).replace(/^0+|0+$/g, '')), 'hex');

  return bufferValue.toString('utf8');
}