当前位置:网站首页>C# 40. Byte[] to hexadecimal string
C# 40. Byte[] to hexadecimal string
2022-06-26 05:10:00 【lljss2020】
1. Code
//byte[] turn 16 Base number string
//0x13 0xab 0xef -> “13ABEF”
public string BytesToHexString(byte[] bytes,int offset, int length)
{
string hexString = string.Empty;
if((bytes != null) && (length != 0))
{
StringBuilder strB = new StringBuilder();
for(int i=offset;i<length+offset;i++)
{
strB.Append(bytes[i].ToString("X2"));
}
hexString = strB.ToString();
}
return hexString;
}
//16 Base number string turn byte[]
//“13ABEF” -> 0x13 0xab 0xef
public byte[] StringToHexbytes(string hexString)
{
if (hexString == null) return null;
hexString = hexString.Replace(" ","");
byte[] returnBytes = new byte[hexString.Length/2];
for (int i = 0; i < returnBytes.Length; i++)
{
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
}
return returnBytes;
}
2. test
byte[] a = new byte[] {
0x13,0xAB,0xEF };
string str = BytesToHexString(a,0,3);
byte[] b = StringToHexbytes(str);
边栏推荐
- 6.1 - 6.2 introduction to public key cryptography
- Practical cases | getting started and mastering tkinter+pyinstaller
- 微服务之间的Token传递之一@Feign的token传递
- thread priority
- CMakeLists.txt Template
- How MySQL deletes all redundant duplicate data
- Thoughts triggered by the fact that app applications are installed on mobile phones and do not display icons
- Sentimentin tensorflow_ analysis_ layer
- 钟珊珊:被爆锤后的工程师会起飞|OneFlow U
- ThreadPoolExecutor实现文件上传批量插入数据
猜你喜欢
Zuul 实现动态路由
一个从坟墓里爬出的公司
超高精度定位系统中的UWB是什么
Genius makers: lone Rangers, technology giants and AI | ten years of the rise of in-depth learning
2. < tag dynamic programming and conventional problems > lt.343 integer partition
Anaconda creates tensorflow environment
Protocol selection of mobile IM system: UDP or TCP?
PHP二维/多维数组按照指定的键值来进行升序和降序
天才制造者:獨行俠、科技巨頭和AI|深度學習崛起十年
Codeforces Round #802 (Div. 2)(A-D)
随机推荐
YOLOV5超参数设置与数据增强解析
Computer Vision Tools Chain
6.1 - 6.2 introduction to public key cryptography
Illustration of ONEFLOW's learning rate adjustment strategy
app 应用安装到手机,不显示图标,引发的思考
天才制造者:独行侠、科技巨头和AI|深度学习崛起十年
SSH connected to win10 and reported an error: permission denied (publickey, keyboard interactive)
Cookie and session Basics
【Unity3D】碰撞体组件Collider
pycharm 导包错误没有警告
红队得分方法统计
2.< tag-动态规划和常规问题>lt.343. 整数拆分
Introduction to classification data cotegory and properties and methods of common APIs
skimage.morphology.medial_axis
How to select the data transmission format of instant messaging application
Douban top250
5. <tag-栈和常规问题>补充: lt.946. 验证栈序列(同剑指 Offer 31. 栈的压入、弹出序列)
-Discrete Mathematics - Analysis of final exercises
The best Chinese open source class of vision transformer, ten hours of on-site coding to play with the popular model of Vit!
【Latex】错误类型总结(持更)