get Hex Params Byte - Android java.lang

Android examples for java.lang:Byte

Description

get Hex Params Byte

Demo Code


import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import android.util.Log;

public class Main{
    public static byte[] getHexParamsByte(String hexSrc, int length) {
        byte[] params = new byte[length];
        byte[] srcs;
        srcs = HexStringBytes.String2Bytes(hexSrc);
        if (srcs.length < length) {
            byteArrayReplace(params, srcs, 0, srcs.length);
            for (int i = srcs.length; i < length; i++) {
                params[i] = 0x20;//ww w .j  a  va  2s. c o  m
            }
        } else {
            params = srcs;
        }
        return params;
    }
    
    public static byte[] byteArrayReplace(byte[] a, byte[] b, int start,
            int len) {
        for (int i = start, j = 0; j < len; i++, j++) {
            a[i] = b[j];
        }

        return a;
    }
}

Related Tutorials