Toggle navigation
亻中 阝日
博客
梦瑶
收款
吃鸡
聊天
杰森
更多...
登录
注册
×
登录
邮箱
密码
忘记密码?
Java bytes2hex hex2bytes
•发布于
•作者
liuzy
•1588 次浏览
•最后一次编辑是
•来自
资讯
```java public static String bytes2hex(byte[] bytes) { BigInteger bi = new BigInteger(1, bytes); String hex = bi.toString(16); int paddingLength = (bytes.length * 2) - hex.length(); if (paddingLength > 0) return String.format("%0" + paddingLength + "d", 0) + hex; else return hex; } public static byte[] hex2bytes(String hex) { byte[] bytes = new byte[hex.length() / 2]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16); } return bytes; } public static String bytesToHexStr(byte[] bytes) { if (bytes == null || bytes.length == 0) { return null; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hv = Integer.toHexString(bytes[i] & 0xFF); if (hv.length() == 1) { sb.append(0); } sb.append(hv); } return sb.toString(); } public static byte[] hexStrToBytes(String hexString) { String hex = "0123456789ABCDEF"; if (hexString == null || "".equals(hexString)) { return null; } int length = hexString.length() / 2; char[] hexChars = hexString.toUpperCase().toCharArray(); byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) { int pos = i * 2; bytes[i] = (byte) (hex.indexOf(hexChars[pos]) << 4 | hex.indexOf(hexChars[pos + 1])); } return bytes; } ```
0 回复
作者
liuzy
积分: 823
“ 黑眼圈圈男 ”
无人回复话题
SonarQube 9.4 + PostgreSQL
shell倒计时
日常网络巧技
使用ssh创建socks5代理服务
NodeJS集群demo
作者其他话题
SonarQube 9.4 + PostgreSQL
shell倒计时
日常网络巧技
使用ssh创建socks5代理服务
NodeJS集群demo
回到顶部
友情链接:
JFinal
©2015 Powered by
jfinalbbs
湘ICP备16014575号