当前位置:网站首页>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
边栏推荐
- Pytorch weight decay and dropout
- Ncp1342 chip substitute pn8213 65W gallium nitride charger scheme
- 【L1、L2、smooth L1三类损失函数】
- Principle of redis cluster mode
- C operation XML file
- 查看多台机器所有进程
- Wireless WiFi learning 8-channel transmitting remote control module
- Intern position selection and simplified career development planning in Internet companies
- Network five whip
- XML解析
猜你喜欢
随机推荐
codeforces每日5题(均1700)-第五天
yolov5目标检测神经网络——损失函数计算原理
Install esxi 6.0 interactively
Redis cluster (master-slave) brain crack and solution
[yolov5.yaml parsing]
《看完就懂系列》15个方法教你玩转字符串
【 YOLOv3中Loss部分计算】
简单解决redis cluster中从节点读取不了数据(error) MOVED
MySQL statistical skills: on duplicate key update usage
[deploy pytoch project through onnx using tensorrt]
Vscode shortcut key
Principle and performance analysis of lepton lossless compression
【上采样方式-OpenCV插值】
redis集群中hash tag 使用
【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
[pytorch modifies the pre training model: there is little difference between the measured loading pre training model and the random initialization of the model]
ACID事务理论
手机 CPU 架构类型了解
Hash tag usage in redis cluster
自动化测试生命周期