C语言_按字节输出整型浮点的值

这两天开始看,《深入理解计算机系统》,目前的阶段我很适合看这本书。
这是书上的例题,按单个字节输出。
也在考察内存是大端存储还是小端存储。

#include <stdio.h>

typedef unsigned char *byte_pointer;  // 声明一个字节指针 

void show_bytes(byte_pointer start, int len)
{
	int i = 0;
	for (int i = 0; i < len; i++)
	{
		printf("%2.x",start[i]);
	}
	printf("\n");
}
void show_float(int x)
{
	show_bytes((byte_pointer)&x, sizeof(float));
}
void show_pointer(void *x)
{
	show_bytes((byte_pointer)&x, sizeof(void *));
}
void show_int(int x)
{
	show_bytes((byte_pointer)&x, sizeof(int));
}
int main()
{
	int val = 0x87654321;
	byte_pointer valp = (byte_pointer)&val;
	show_bytes(valp, sizeof(int));

	system("pause");
	return 0;
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值