c语言 hex转str 函数_int printf(const char)

c语言 hex转str 函数_int printf(const char)voidhexDump(constchar*buf,intlen){ if(len<1||buf==NULL)return; constchar*hexChars="0123456789ABCDEF"; inti=0; charc=0x00; charstr_print_able[17]; charstr_hex_buffe…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

void hexDump(const char* buf, int len)
{
	if (len < 1 || buf == NULL) return;

	const char *hexChars = "0123456789ABCDEF";
	int i = 0;
	char c = 0x00;
	char str_print_able[17];
	char str_hex_buffer[16 * 3 + 1];

	for (i = 0; i < (len / 16) * 16; i += 16)
	{
		int j = 0;
		for (j = 0; j < 16; j++)
		{
			c = buf[i + j];

			// hex
			int z = j * 3;
			str_hex_buffer[z++] = hexChars[(c >> 4) & 0x0F];
			str_hex_buffer[z++] = hexChars[c & 0x0F];
			str_hex_buffer[z++] = (j < 10 && !((j + 1) % 8)) ? '_' : ' ';

			// string with space repalced
			if (c < 32 || c == '
void hexDump(const char* buf, int len)
{
if (len < 1 || buf == NULL) return;
const char *hexChars = "0123456789ABCDEF";
int i = 0;
char c = 0x00;
char str_print_able[17];
char str_hex_buffer[16 * 3 + 1];
for (i = 0; i < (len / 16) * 16; i += 16)
{
int j = 0;
for (j = 0; j < 16; j++)
{
c = buf[i + j];
// hex
int z = j * 3;
str_hex_buffer[z++] = hexChars[(c >> 4) & 0x0F];
str_hex_buffer[z++] = hexChars[c & 0x0F];
str_hex_buffer[z++] = (j < 10 && !((j + 1) % 8)) ? '_' : ' ';
// string with space repalced
if (c < 32 || c == '\0' || c == '\t' || c == '\r' || c == '\n' || c == '\b')
str_print_able[j] = '.';
else
str_print_able[j] = c;
}
str_hex_buffer[16 * 3] = 0x00;
str_print_able[j] = 0x00;
printf("%04x  %s %s\n", i, str_hex_buffer, str_print_able);
}
// 处理剩下的不够16字节长度的部分
int leftSize = len % 16;
if (leftSize < 1) return;
int j = 0;
int pos = i;
for (; i < len; i++)
{
c = buf[i];
// hex
int z = j * 3;
str_hex_buffer[z++] = hexChars[(c >> 4) & 0x0F];
str_hex_buffer[z++] = hexChars[c & 0x0F];
str_hex_buffer[z++] = ' ';
// string with space repalced
if (c < 32 || c == '\0' || c == '\t' || c == '\r' || c == '\n' || c == '\b')
str_print_able[j] = '.';
else
str_print_able[j] = c;
j++;
}
str_hex_buffer[leftSize * 3] = 0x00;
str_print_able[j] = 0x00;
for (j = leftSize; j < 16; j++)
{
int z = j * 3;
str_hex_buffer[z++] = ' ';
str_hex_buffer[z++] = ' ';
str_hex_buffer[z++] = ' ';
}
str_hex_buffer[16 * 3] = 0x00;
printf("%04x  %s %s\n", pos, str_hex_buffer, str_print_able);
}
' || c == '\t' || c == '\r' || c == '\n' || c == '\b') str_print_able[j] = '.'; else str_print_able[j] = c; } str_hex_buffer[16 * 3] = 0x00; str_print_able[j] = 0x00; printf("%04x %s %s\n", i, str_hex_buffer, str_print_able); } // 处理剩下的不够16字节长度的部分 int leftSize = len % 16; if (leftSize < 1) return; int j = 0; int pos = i; for (; i < len; i++) { c = buf[i]; // hex int z = j * 3; str_hex_buffer[z++] = hexChars[(c >> 4) & 0x0F]; str_hex_buffer[z++] = hexChars[c & 0x0F]; str_hex_buffer[z++] = ' '; // string with space repalced if (c < 32 || c == '
void hexDump(const char* buf, int len)
{
if (len < 1 || buf == NULL) return;
const char *hexChars = "0123456789ABCDEF";
int i = 0;
char c = 0x00;
char str_print_able[17];
char str_hex_buffer[16 * 3 + 1];
for (i = 0; i < (len / 16) * 16; i += 16)
{
int j = 0;
for (j = 0; j < 16; j++)
{
c = buf[i + j];
// hex
int z = j * 3;
str_hex_buffer[z++] = hexChars[(c >> 4) & 0x0F];
str_hex_buffer[z++] = hexChars[c & 0x0F];
str_hex_buffer[z++] = (j < 10 && !((j + 1) % 8)) ? '_' : ' ';
// string with space repalced
if (c < 32 || c == '\0' || c == '\t' || c == '\r' || c == '\n' || c == '\b')
str_print_able[j] = '.';
else
str_print_able[j] = c;
}
str_hex_buffer[16 * 3] = 0x00;
str_print_able[j] = 0x00;
printf("%04x  %s %s\n", i, str_hex_buffer, str_print_able);
}
// 处理剩下的不够16字节长度的部分
int leftSize = len % 16;
if (leftSize < 1) return;
int j = 0;
int pos = i;
for (; i < len; i++)
{
c = buf[i];
// hex
int z = j * 3;
str_hex_buffer[z++] = hexChars[(c >> 4) & 0x0F];
str_hex_buffer[z++] = hexChars[c & 0x0F];
str_hex_buffer[z++] = ' ';
// string with space repalced
if (c < 32 || c == '\0' || c == '\t' || c == '\r' || c == '\n' || c == '\b')
str_print_able[j] = '.';
else
str_print_able[j] = c;
j++;
}
str_hex_buffer[leftSize * 3] = 0x00;
str_print_able[j] = 0x00;
for (j = leftSize; j < 16; j++)
{
int z = j * 3;
str_hex_buffer[z++] = ' ';
str_hex_buffer[z++] = ' ';
str_hex_buffer[z++] = ' ';
}
str_hex_buffer[16 * 3] = 0x00;
printf("%04x  %s %s\n", pos, str_hex_buffer, str_print_able);
}
' || c == '\t' || c == '\r' || c == '\n' || c == '\b') str_print_able[j] = '.'; else str_print_able[j] = c; j++; } str_hex_buffer[leftSize * 3] = 0x00; str_print_able[j] = 0x00; for (j = leftSize; j < 16; j++) { int z = j * 3; str_hex_buffer[z++] = ' '; str_hex_buffer[z++] = ' '; str_hex_buffer[z++] = ' '; } str_hex_buffer[16 * 3] = 0x00; printf("%04x %s %s\n", pos, str_hex_buffer, str_print_able); }

c语言 hex转str 函数_int printf(const char)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/190890.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号