yy1717
2020-08-21 b8b0a1e54b2d5bc78f2e3ba3561943b959db618a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.safeluck.aykj.decoder;
 
import com.safeluck.aykj.annotation.Int32;
import com.safeluck.aykj.utils.BytesUtils;
 
/**
 * Created by zhouwei on 2016/12/1.
 */
public class Int32Coder extends BaseDecoder<Integer> {
 
    public static Int32Coder instance = new Int32Coder();
 
    @Override
    public Integer decode(String str) {
        if(str==null||"".equals(str))
            return 0;
        return Integer.valueOf(str, 16);
    }
 
    @Override
    public String encode(Integer i) {
        if(i==null)
            i=0;
        //高位在前 32位整数
        int num = i.intValue();
        byte[] b = new byte[4];
        b[3]= (byte)(num&0xff);
        b[2]= (byte)(num >> 8);
        b[1]= (byte)(num >> 16);
        b[0]= (byte)(num >> 24);
        return BytesUtils.bytesToHexString(b);
    }
}