본문 바로가기

Android

hex to byte, byte to hex

[code]
    private byte[] hexToBytes(final String hex) {
        byte[] bytes = new byte[hex.length() / 2];
        for (int i = 0; i < bytes.length; i++) {
            bytes[i] = (byte)Integer.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
        }
        
        return bytes;
    }


    private String bytesToHex(final byte[] bytes) {
        final StringBuffer buffer = new StringBuffer();
        for (byte b : bytes) {
            final int i = b & 0xFF;
            if (i < 16) {
                buffer.append('0');
            }
            buffer.append(Integer.toString(i, 16));
        }
        return buffer.toString();
    }
[/code]

code by jinahya

'Android' 카테고리의 다른 글

options menu  (0) 2013.10.08
tripledes  (0) 2013.10.08
redirecting and cookie data  (0) 2013.10.08
WebViewClient error code  (0) 2013.10.08
maven android plugin  (0) 2013.10.08