栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

2.55-在你能够访问的不同机器上,使用show

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2.55-在你能够访问的不同机器上,使用show

#include 

//A byte pointer refers to a sequence of bytes
typedef unsigned char * byte_pointer;

//The input is a byte pointer and a byte number
void show_bytes(byte_pointer start,size_t len){  
	size_t i;
	for (i = 0; i < len; i++) {
		//A storage unit holds one byte
		printf("%.2x",start[i]);  
		//Output in hexadecimal format with at least two digits
	}
	printf("n");
}

void show_int(int x) {
	show_bytes((byte_pointer) &x, sizeof(int));
}

void show_float(float x) {
	show_bytes((byte_pointer) &x, sizeof(float));
}

void show_pointer(void *x) {
	show_bytes((byte_pointer) &x, sizeof(void *));
}


void test_show_bytes(int val) {
	int ival = val;
	float fval = (float)ival;
	int *pval = &ival;
	show_int(ival);
	show_float(fval);
	show_pointer(pval);
}

int main() {
	int t = 12345;
	test_show_bytes(t);
	return 0;
}

机器为 intel x86-64处理器:
在windows上:
(1)编译器x86,得到的地址为4字节

(2)编译器x64,得到的地址为8字节

同一台机子上的linux虚拟机:

这里我们使用的样例数字为12345 = 0x00003039 float ——0x4640e400
intel 是小端法机器,linux64使用8字节地址

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/828313.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号