809协议服务端程序解码程序
- 目录
- 概述
- 需求:
- 设计思路
- 实现思路分析
- 1.服务端
- 2.code:
- 拓展实现
- 性能参数测试:
- 1.功能测试
- 参考资料和推荐阅读
Survive by day and develop by night.
talk for import biz , show your perfect code,full busy,skip hardness,make a better result,wait for change,challenge Survive.
happy for hardess to solve denpendies.
目录
概述
809协议服务端程序
需求:
设计思路
实现思路分析
1.服务端
809协议服务端程序解码程序:
2.code:
package cn.com.onlinetool.jt809.convert;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class StringToHex{
public String convertStringToHex(String str){
char[] chars = str.toCharArray();
StringBuffer hex = new StringBuffer();
for(int i = 0; i < chars.length; i++){
hex.append(Integer.toHexString((int)chars[i]));
}
return hex.toString();
}
public String convertHexToString(String hex){
StringBuilder sb = new StringBuilder();
StringBuilder temp = new StringBuilder();
//49204c6f7665204a617661 split into two characters 49, 20, 4c...
for( int i=0; i<hex.length()-1; i+=2 ){
//grab the hex in pairs
String output = hex.substring(i, (i + 2));
//convert hex to decimal
int decimal = Integer.parseInt(output, 16);
//convert the decimal to character
sb.append((char)decimal);
temp.append(decimal);
}
return sb.toString();
}
//504F533838383834 POS88884
public static void main(String[] args) {
StringToHex strToHex = new StringToHex();
// System.out.println("\n-----ASCII码转换为16进制 -----");
// String str = "POS88884";
// System.out.println("字符串: " + str);
// String hex = strToHex.convertStringToHex(str);
// System.out.println("转换为16进制 : " + hex);
// String hex="3132333435363738393031000000000000000000";
// String hex="3132333435364071712E636F6D";
String hex="63E5A282B2E2413838383838";
System.out.println("\n***** 16进制转换为ASCII *****");
System.out.println("Hex : " + hex);
System.out.println("ASCII : " + strToHex.convertHexToString(hex));
}
public static void main2(String[] args) {
String s = "000000005BAC4D50";
long longVaue = new BigInteger(s, 16).longValue();
Calendar c=Calendar.getInstance();
c.setTimeInMillis(longVaue);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(dateFormat.format(c.getTime()));
}
}
拓展实现
这里参考:github:简单实现上述流程:
入门级实现:
: 部分源码实现.
: 源码实现
性能参数测试:
1.功能测试
参考资料和推荐阅读
- 暂无
欢迎阅读,各位老铁,如果对你有帮助,点个赞加个关注呗!同时,期望各位大佬的批评指正~