当前位置:网站首页>C [byte array] and [hexadecimal string] mutual conversion - codeplus series
C [byte array] and [hexadecimal string] mutual conversion - codeplus series
2022-07-01 09:54:00 【Great ape】
C# [ Byte array ] And [16 Base string ] Interconversion
List of articles
Preface
Hexadecimal ( Shorthand for hex Subscript or subscript 16) Is a base number of 16 Our counting system , It's a kind of meeting 16 Into the 1 Carry system . Usually numbers 0、1、2、3、4、5、6、7、8、9 And letters A、B、C、D、E、F(a、b、c、d、e、f) Express , among :AF Express 1015, These are called hexadecimal numbers .
We are in the process of development , It is often necessary to print out the received and sent data for inspection . How to simply and efficiently convert a byte array to a string in one line of code ? Let's have a look !
Sample code
[ Byte array ] turn [16 Base string ]
byte[] bytes = new byte[] {
0xAA, 0xBB, 0xCC, 0x01, 0x02, 0x03 };
Console.WriteLine($" Hexadecimal string ( Default ):\n{
bytes.ToHexString()}");
Console.WriteLine($" Hexadecimal string ( Uppercase with space ):\n{
bytes.ToHexString("{0:X2} ")}");
Console.WriteLine($" Hexadecimal string ( Lowercase with spaces ):\n{
bytes.ToHexString("{0:x2} ")}");
Console.WriteLine($" Hexadecimal code string :\n{
bytes.ToHexCodeString()}");
The results are shown in the following figure :
[16 Base string ] turn [ Byte array ]
string hex = "AABBCC010203";
var bytes = hex.HexStringToBytes();
introduce CodePlus
The main reason why the transformation is so simple is that it refers to CodePlus Extension method provided .
Right click the item , choice management NuGet Package 
Enter... In the search field CodePlus, After selecting the package in the figure , Select Install .

边栏推荐
- 奇怪,为什么ArrayList初始化容量大小为10?
- Fried money, lost 10million.
- Write your own who commands
- 一个悄然崛起的国产软件,低调又强大!
- 主流实时流处理计算框架Flink初体验
- 121. thread scheduling: join() method and yield() method
- SQL学习笔记(03)——数据约束关系
- Some tools used in embedded development
- 历史上的今天:九十年代末的半导体大战;冯·诺依曼发表第一份草案;CBS 收购 CNET...
- Flinkv1.13 implementation of financial anti fraud cases
猜你喜欢

MapReduce programming basics

Scratch big fish eat small fish Electronic Society graphical programming scratch grade examination level 2 true questions and answers analysis June 2022

Finally, someone made it clear what DRAM and NAND flash are

Eat a rich woman's melon...

leetcode:111. 二叉树的最小深度

全球基金和资管的股票建仓率达到15年内新低

7-Zip 遭抵制?呼吁者定下“三宗罪”:伪开源、不安全、作者来自俄罗斯!

Flinkv1.13 implementation of financial anti fraud cases

This is the best flash popular science article I have ever seen!

What is cloud primordial? Will it be the trend of future development?
随机推荐
Who has the vision to cross the cycle?
遇到女司机业余开滴滴,日入500!
It is interesting to understand MMAP in this way!
CSDN一站式云服务开放内测,诚邀新老用户来抢鲜
uniapp微信小程序组件按需引入
华为帐号多端协同,打造美好互联生活
SQL learning notes (01) - basic knowledge of database
Sleeping second brother...
PHP array functions (merge, split, append, find, delete, etc.)
奇怪,为什么ArrayList初始化容量大小为10?
谁还在买“三只松鼠”们
How to understand JS promise
7-Zip 遭抵制?呼吁者定下“三宗罪”:伪开源、不安全、作者来自俄罗斯!
Matrix and coordinates
TC8:UDP_USER_INTERFACE_01-08
Clickhouse: Test on query speed of A-share minute data [Part 2]
PHP code audit and File Inclusion Vulnerability
SQL学习笔记(01)——数据库基本知识
Voice service notes
Module 9: design e-commerce seckill system