package com.safeluck.aykj.decoder;
|
|
import com.safeluck.aykj.utils.BytesUtils;
|
|
/**
|
* Created by zhouwei on 2016/12/1.
|
*/
|
public class Int16LECoder extends BaseDecoder<Integer> {
|
|
public static Int16LECoder instance = new Int16LECoder();
|
|
@Override
|
public Integer decode(String str) {
|
|
byte[] src = BytesUtils.hexStringToBytes(str);
|
int offset = 0;
|
int value;
|
value = (src[offset] & 0xFF)
|
| ((src[offset + 1] & 0xFF) << 8);
|
// | ((src[offset + 2] & 0xFF) << 16)
|
// | ((src[offset + 3] & 0xFF) << 24));
|
return value;
|
// return Integer.valueOf(Short.reverseBytes(Int16Coder.instance.decode(str).shortValue())&0xFF);
|
// if(str==null||"".equals(str))
|
// return 0;
|
//
|
// return Integer.valueOf(str, 16);
|
}
|
|
@Override
|
public String encode(Integer i) {
|
if(i==null)
|
i=0;
|
int value = i.intValue();
|
byte[] src = new byte[2];
|
// src[3] = (byte) ((value >> 24) & 0xFF);
|
// src[2] = (byte) ((value >> 16) & 0xFF);
|
src[1] = (byte) ((value >> 8) & 0xFF);
|
src[0] = (byte) (value & 0xFF);
|
return BytesUtils.bytesToHexString(src);
|
}
|
}
|