1
2
3
Byte[] bytes = (Byte[]) arrayList.toArray(); //  ArrayList -> Byte[]
 
arrayList = new ArrayList(Arrays.asList(bytes )); // Byte[] -> ArrayList
cs


(만약 프리미티브 byte[]로 전환하고자 하신다면, Bytes[X].byteValue() 를 X값을 루프를 돌면서 복사해주면됩니다.)


출처 : http://mungi.kr/177



1
2
3
4
5
6
7
8
9
10
11
12
13
14
        int Decint = Integer.parseInt(Dec); 
        byte [] bytes = {0x00,0x00};
        String hexto04="";
        String hex = Integer.toHexString(Decint);
        if(Decint<0)
        {
            hexto04 = hex.substring(hex.length()-4);
            bytes = new java.math.BigInteger(hexto04,16).toByteArray();
        }
        else if(Decint>0)
        {
            bytes = new java.math.BigInteger(hex,16).toByteArray();
        }
        return bytes ;
cs

출처 : http://ecogeo.tistory.com/129


위의 hexString to byte 같은 경우 음수가 들어오면 변환은 내가 대충 짜본것이다.



추가 

wrapper 가 아닌 primetive byte[] 전환 

1
2
3
4
byte [] bytes =  new byte[sendbyte.size()];
            for (int i = ; i<sendbyte.size();i++){
                bytes[i]= sendbyte.get(i);
            }
cs


+ Recent posts