In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to realize the conversion from ASCII to HEX under linux. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
In the project development process, it is sometimes necessary to convert a string of hexadecimal text into a hexadecimal array. This is the way to do this:
# include # include / * isspace,toupper header file * / # include / * uint8_t header file * / / * remove spaces in the array * / char * trim (char * str) {if (str = = NULL | | * str = ='\ 0') return NULL; int len = strlen (str); char * p = str While (* p! ='\ 0') {while (isspace (* p)) {memmove (pamph1) + 1);} return str;} / * ascii to hexadecimal array, failure returns-1, success returns 0*/int ascii2hex (const char * string,int length,uint8_t hex [], int * hexlen) {char src_ ARR [+ 2] / * the first digit of odd characters is'0', and the string Terminator is'\ 0', so it is + 2'/ int src_len=0,i; char ah,al; uint8_t ih,il; if (string = = NULL | | hex = = NULL | | length'9')? (toupper (ah) -'A' + 10): (ah -'0'); il = (al >'9')? (toupper (al) -'A' + 10): (al -'0'); hex [I] = ih * 16 + il;} return 0;} / * hexadecimal conversion ascii, failed to return-1, successfully returned 0*/int hex2ascii (uint8_t * src, char dest [], int len) {uint8_t dh,dl; / / string high and low int i; if (src = = NULL | | dest = = NULL | | len
< 1){ return -1; } for(i = 0; i < len; i++){ dh = src[i] / 16; dh = (dh >9)? (dh-10+'A'): (dh +'0'); dl = src [I]% 16; dl = (dl > 9)? (dl-10+'A'): (dl +'0'); dest [2Secreti] = dh; dest [2*i+1] = dl;} dest [2Secreti] ='\ 0bread; return 0;} after reading the above, do you have any further understanding of how to convert ASCII to HEX under linux? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.