I have the following code which is used to encode byte array to HEX string
private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
public static void WriteHexBytes(byte[] data, StringBuilder sb)
{
char[] chars = new char[data.length*2];
for (int i = 0; i < data.length; ++i)
{
chars[2*i] = HEX_CHARS[(data[i] & 0xF0) >>> 4];
chars[2*i + 1] = HEX_CHARS[data[i] & 0x0F];
}
sb.append(chars);
}
The for
loop is very slow, it takes about 10 seconds
to encode 3MB
of bytes on real device. On the emulator it takes like forever.
The sb.append
is performed instantly.
Is this normal? It seems very slow to me? What is causing slowness?
Tested on Samsung Galaxy Tab 2 7.0