当前位置:网站首页>byte2String、string2Byte
byte2String、string2Byte
2022-07-05 12:02:00 【Back end coder】
byte2String、string2Byte
package cn.com.codingce;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
public class ByteToString {
public static void main(String[] args) {
System.out.println(Arrays.toString(ByteToString.byte2String("f0401c4db9ec49b6b3bd557eea8c8a73b860ed6062cb2472e2f66135e0a727d6")));
System.out.println(ByteToString.string2Byte(new byte[]{
102, 48, 52, 48, 49, 99, 52, 100, 98, 57, 101, 99, 52, 57, 98, 54, 98, 51, 98, 100, 53, 53, 55, 101, 101, 97, 56, 99, 56, 97, 55, 51, 98, 56, 54, 48, 101, 100, 54, 48, 54, 50, 99, 98, 50, 52, 55, 50, 101, 50, 102, 54, 54, 49, 51, 53, 101, 48, 97, 55, 50, 55, 100, 54}));
byte[] bytes = ByteToString.byte2String("f0401c4db9ec49b6b3bd557eea8c8a73b860ed6062cb2472e2f66135e0a727d6");
StringBuffer stringBuffer = new StringBuffer();
for (int i : bytes) {
stringBuffer.append("(byte)0x");
stringBuffer.append(turn16(i));
stringBuffer.append(", ");
}
System.out.println(stringBuffer);
}
public static byte[] byte2String(String AppSign) {
byte[] bytes = new byte[AppSign.length()];
try {
bytes = AppSign.getBytes("utf-8");
return bytes;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return new byte[]{
};
}
public static String string2Byte(byte[] bytes) {
try {
return new String(bytes, "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "";
}
public static String turn16(int num){
String shortTimeNum = "";
int remainder = 0;
String tempStr = "";
/** * Analog short division */
while(num >= 1){
remainder = num % 16;
tempStr = getOtherNum(remainder);
num = num / 16;
shortTimeNum = tempStr + shortTimeNum;
}
return shortTimeNum;
}
/** * 16 Special processing in base conversion , Need to put more than 9 To convert numbers into letters * @param tempNum * @return */
public static String getOtherNum(int tempNum){
String tempStr = "";
if(tempNum > 9){
switch(tempNum){
case 10:
tempStr = "A";
break ;
case 11:
tempStr = "B";
break;
case 12:
tempStr = "C";
break;
case 13:
tempStr = "D";
break;
case 14:
tempStr = "E";
break;
case 15:
tempStr = "F";
break;
}
}else{
tempStr = String.valueOf(tempNum);
}
return tempStr;
}
}
Output
/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=51239:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/lib/tools.jar:/Volumes/Victory/mxz-code/other/test/out/production/test cn.com.codingce.ByteToString
[102, 48, 52, 48, 49, 99, 52, 100, 98, 57, 101, 99, 52, 57, 98, 54, 98, 51, 98, 100, 53, 53, 55, 101, 101, 97, 56, 99, 56, 97, 55, 51, 98, 56, 54, 48, 101, 100, 54, 48, 54, 50, 99, 98, 50, 52, 55, 50, 101, 50, 102, 54, 54, 49, 51, 53, 101, 48, 97, 55, 50, 55, 100, 54]
f0401c4db9ec49b6b3bd557eea8c8a73b860ed6062cb2472e2f66135e0a727d6
(byte)0x66, (byte)0x30, (byte)0x34, (byte)0x30, (byte)0x31, (byte)0x63, (byte)0x34, (byte)0x64, (byte)0x62, (byte)0x39, (byte)0x65, (byte)0x63, (byte)0x34, (byte)0x39, (byte)0x62, (byte)0x36, (byte)0x62, (byte)0x33, (byte)0x62, (byte)0x64, (byte)0x35, (byte)0x35, (byte)0x37, (byte)0x65, (byte)0x65, (byte)0x61, (byte)0x38, (byte)0x63, (byte)0x38, (byte)0x61, (byte)0x37, (byte)0x33, (byte)0x62, (byte)0x38, (byte)0x36, (byte)0x30, (byte)0x65, (byte)0x64, (byte)0x36, (byte)0x30, (byte)0x36, (byte)0x32, (byte)0x63, (byte)0x62, (byte)0x32, (byte)0x34, (byte)0x37, (byte)0x32, (byte)0x65, (byte)0x32, (byte)0x66, (byte)0x36, (byte)0x36, (byte)0x31, (byte)0x33, (byte)0x35, (byte)0x65, (byte)0x30, (byte)0x61, (byte)0x37, (byte)0x32, (byte)0x37, (byte)0x64, (byte)0x36,
Process finished with exit code 0
边栏推荐
- liunx禁ping 详解traceroute的不同用法
- Splunk configuration 163 mailbox alarm
- How to protect user privacy without password authentication?
- Simply solve the problem that the node in the redis cluster cannot read data (error) moved
- Principle and performance analysis of lepton lossless compression
- splunk配置163邮箱告警
- Network five whip
- Halcon 模板匹配实战代码(一)
- 【使用TensorRT通过ONNX部署Pytorch项目】
- Troubleshooting of high memory usage of redis in a production environment
猜你喜欢

【yolov3损失函数】

12.(地图数据篇)cesium城市建筑物贴图

【无标题】

《增长黑客》阅读笔记

Yolov 5 Target Detection Neural Network - Loss Function Calculation Principle

【Win11 多用户同时登录远程桌面配置方法】

Matlab boundarymask function (find the boundary of the divided area)

【L1、L2、smooth L1三类损失函数】

Uniapp + unicloud + Unipay realize wechat applet payment function

7月华清学习-1
随机推荐
The solution of outputting 64 bits from printf format%lld of cross platform (32bit and 64bit)
Thoughts and suggestions on the construction of intelligent management and control system platform for safe production in petrochemical enterprises
Principle of redis cluster mode
想问问,如何选择券商?在线开户是很安全么?
《增长黑客》阅读笔记
多表操作-自关联查询
13.(地图数据篇)百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
Hiengine: comparable to the local cloud native memory database engine
XML parsing
【主流Nivida显卡深度学习/强化学习/AI算力汇总】
【load dataset】
Redis集群的重定向
[calculation of loss in yolov3]
[pytorch pre training model modification, addition and deletion of specific layers]
Liunx prohibit Ping explain the different usage of traceroute
Riddle 1
什么是数字化存在?数字化转型要先从数字化存在开始
Open3d European clustering
How to clear floating?
【SingleShotMultiBoxDetector(SSD,单步多框目标检测)】