In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article "C language hexadecimal and ASCII character conversion method is what" most people do not understand, so the editor summed up the following content, detailed, clear steps, with a certain reference value, I hope you can read this article can be rewarded, let's take a look at this "C language hexadecimal and ASCII character conversion method is what" article.
1. Convert the obtained hexadecimal data into ASCII characters of the same character, for example: get [2] = {0x11recover0x22}; → put [4] = {'1Chronome2Q 2x2}
Data conversion is mainly done through sprintf ();. There are many explanations for this function on the web. If you want to know more, you can check it out.
Typedef unsigned char uint8_t;char data [64]; uint8_t * hex_to_ascii (uint8_t * str, uint32_t len) {uint8_t * hex_buf = str; for (int I = 0; I
< len; i++) { sprintf(&data[i * 2], "X", hex_buf[i]); } return (uint8_t *)data;} 2、 把获取到的ASCII字符转换成相同字符的16进制,例:get[4]={'a','a','b','b'}; → put[2] = {0xaa,0xbb}; ASCII转换成16进制主要通过sscanf();来完成的。 typedef unsigned char uint8_t;char data[64];uint8_t *ascii_to_hex(char *str, uint32_t len){ char *str_buf = str; uint8_t *hex = (uint8_t *)data; uint8_t data_buf[len]; for (int i = 0; i < len; i++) { sscanf(str_buf, "x", (int *)&data_buf[i]); str_buf += 2; } memcpy(hex, data_buf, len); return hex;} 3、把获取到的16进制转换成对应的ASCII字符,例:get[4]={'a','a','b','b'}; → put[4]={0x61,0x61,0x62,0x62}; typedef unsigned char uint8_t;char data[64];uint8_t *Char_to_Hex(char *str,uint32_t len){ char *hex_buf = str; uint8_t *hex = (uint8_t *)data; for (int i = 0; i < len; i++) { if ((hex_buf[i] >='0') & (hex_ BUF [I] ='a') & & (hex_ BUF [I] ='A') & & (hex_ BUF [I] = 0x30) & & (hex_ BUF [I] = 0x41) & (hex_ BUF [I] = 0x61) & (hex_ BUF [I]
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.