java 通过阿里物联网平台推送数据到显示屏
显示屏支持格式:数字、字符
发送内容:温度过高
字符串参数格式转换流程:字符串拆分字符,字符转GB2312编码,再转16进制,再转10进制
public static void main(String[] args) throws Exception {
String text = "温度过高"; // 待转换的文字
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
charToInt(c);
}
}
public static int charToInt(char c) {
int decimalValue = 0;
try {
System.out.println(c);
//字符转GB2312
byte[] gb2312s = Convert.toStr(c).getBytes("GB2312");
//转16进制
String s = bytesToHex(gb2312s);
System.out.println(s);
//转10进制
decimalValue = Integer.parseInt(s, 16);
System.out.println("十六进制数 CEC2 对应的十进制数是: " + decimalValue);
} catch (Exception e) {
e.printStackTrace();
}
return decimalValue;
}
//转16进制
public static String bytesToHex(byte[] bytes) {
String hex = new BigInteger(1, bytes).toString(16);
return hex;
}
执行main方法输出:
温
cec2
十六进制数 CEC2 对应的十进制数是: 52930
度
b6c8
十六进制数 CEC2 对应的十进制数是: 46792
过
b9fd
十六进制数 CEC2 对应的十进制数是: 47613
高
b8df
十六进制数 CEC2 对应的十进制数是: 47327