当前位置:网站首页>byte2String、string2Byte
byte2String、string2Byte
2022-07-05 11:53:00 【后端码匠】
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 = "";
/** * 模拟短除法 */
while(num >= 1){
remainder = num % 16;
tempStr = getOtherNum(remainder);
num = num / 16;
shortTimeNum = tempStr + shortTimeNum;
}
return shortTimeNum;
}
/** * 16进制转换中的特殊处理,需要把大于9的数字转换成字母 * @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;
}
}
输出
/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
边栏推荐
- Mysql统计技巧:ON DUPLICATE KEY UPDATE用法
- Vscode shortcut key
- Implementation of array hash function in PHP
- SET XACT_ABORT ON
- [singleshotmultiboxdetector (SSD, single step multi frame target detection)]
- Pytorch linear regression
- pytorch-多层感知机MLP
- 汉诺塔问题思路的证明
- [yolov3 loss function]
- [configuration method of win11 multi-user simultaneous login remote desktop]
猜你喜欢
[deploy pytoch project through onnx using tensorrt]
Check the debug port information in rancher and do idea remote JVM debug
Network five whip
Principle of persistence mechanism of redis
【yolov5.yaml解析】
mmclassification 训练自定义数据
COMSOL -- 3D casual painting -- sweeping
[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
[crawler] bugs encountered by wasm
【使用TensorRT通过ONNX部署Pytorch项目】
随机推荐
Implementation of array hash function in PHP
跨平台(32bit和64bit)的 printf 格式符 %lld 输出64位的解决方式
Codeworks 5 questions per day (1700 average) - day 5
Mysql统计技巧:ON DUPLICATE KEY UPDATE用法
Open3d European clustering
【load dataset】
【yolov5.yaml解析】
SET XACT_ABORT ON
2048游戏逻辑
Riddle 1
pytorch-线性回归
How to get a token from tokenstream based on Lucene 3.5.0
Yolov5 target detection neural network -- calculation principle of loss function
[pytorch pre training model modification, addition and deletion of specific layers]
Vscode shortcut key
871. Minimum Number of Refueling Stops
pytorch-权重衰退(weight decay)和丢弃法(dropout)
Redis集群(主从)脑裂及解决方案
yolov5目標檢測神經網絡——損失函數計算原理
Web API配置自定义路由