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 == '\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语言 hex转str 函数_int printf(const char)

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Android颜色对照表 或html css RGB颜色对照表[通俗易懂]

    Android颜色对照表 或html css RGB颜色对照表[通俗易懂]颜色代码大全 AA指定透明度。00是完全透明。FF是完全不透明。超出取值范围的值将被恢复为默认值。    ffff00ffff33ffff66ffff99ffffccffffffffcc00ffcc33ffcc66ffcc99ffccccffccffff9900

    2022年5月13日
    71
  • Java0xffffffff为什么表示为-1

    Java0xffffffff为什么表示为-1inti=0xffffffff;System.out.println(i);输出-1上面的程序有个问题为什么inti=0xffffffff;没有报溢出错误,且输出为-1?因为0xffffffff实际是二进制,程序中任何十进制,八进制,16进制的数在计算机底层都是二进制,表示成X进制只是为了让人看明白,所以0xffffffff在电脑中就是32个1,而不是2的32次…

    2022年5月16日
    39
  • vue获取当前路由的子路由列表

    vue获取当前路由的子路由列表this router 获取全局路由 this route 获取当前路由信息 computed 获取当前路由的子路由 routes varroutes children this router options routes varroute this route mat

    2025年6月28日
    1
  • VR虚拟现实开发_vr虚拟世界

    VR虚拟现实开发_vr虚拟世界Here,you’llgettoknowaboutVirtualRealityandhowyoushouldstepbystepstartdevelopingaVRApplicationandkeepyourfirstfootintheVRDevelopmentaura.在这里,您将了解虚拟现实以及如何逐步开始开发VR应用程序,并使您的…

    2022年9月12日
    2
  • idea mybatis跳转插件_idea添加本地jar包到maven

    idea mybatis跳转插件_idea添加本地jar包到maven我相信目前在绝大部分公司里,主要使用的框架是S(spring)S(springMVC)M(mybatis),其中mybatis总体架构是编写mapper接口,框架扫描其对应的mapper.xml文件,由于xml里面编写大量的sql语句,所以在平时调试中需要对其进行调试,但是xml文件并不能像java文件一样,能快速进行跳转,对查找对应xml文件带来巨大的不便。网友基础idea强大的插件系…

    2022年10月6日
    1
  • python矩阵转置与zip(*)的使用

    python矩阵转置与zip(*)的使用Python中的矩阵转置方法有如下几种:使用双重循环做(最直接,最本质的方法)importrandomrow=3column=4array=[[random.randint(0,10)for_inrange(column)]for_inrange(row)]print(“砸门先随机创建一个呗:”,array)res=[]foriinrange(column):tmp=[]forjinrange(row):tmp.

    2022年6月2日
    52

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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