本文介绍了每字节读取一个双var字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 是否可以一次读取一个双字节变量。 我希望将每个字节存储到unsigned char中然后重新组合 再次出现双变量。 thanx Andrea 解决方案 也许: int i; union { double f; unsigned char ftab [sizeof(double)]; } double_bytes; double_bytes.f = 123.54; for(i = 0; i< sizeof(double); ++ i) { printf("%d \ t",double_bytes.ftab [i]); } for(i = 0; i< sizeof(double); ++ i) { double_bytes.ftab [i] = 0; } printf(" \ n%f\ n",double_bytes.f); - Pierre 也许: int i; union { double f; unsigned char ftab [sizeof(double)]; } double_bytes; double_bytes.f = 123.54; for(i = 0;我<的sizeof(双); ++ i) { printf("%d \ t",double_bytes.ftab [i]); } for(i = 0 ; i< sizeof(double); ++ i) {/ / / / / / / / / / / / / / / n%f \ n",double_bytes.f); 好的, 但是如何将double复制到unsigned char vector? 在你的代码中只初始化0值的向量。 也许问题是我的英语;-) (我的意大利语更差)。 但是: double any_float = 123.456; union { double f; unsigned char ftab [sizeof(double)]; } double_bytes; double_bytes.f = any_float; 初始化vector double_bytes.ftab [] _float字节,没有? - Pierre Hi,is it possible to read a double variable one byte at a time.I would want store each byte into unsigned char and then assemble againthe double variable again. thanx Andrea 解决方案 Maybe:int i;union {double f;unsigned char ftab[sizeof(double)];}double_bytes; double_bytes.f = 123.54; for(i = 0; i < sizeof(double); ++i){printf("%d\t", double_bytes.ftab[i]);} for(i = 0; i < sizeof(double); ++i){double_bytes.ftab[i] = 0;} printf("\n%f\n", double_bytes.f); --Pierre Maybe: int i; union { double f; unsigned char ftab[sizeof(double)]; }double_bytes; double_bytes.f = 123.54; for(i = 0; i < sizeof(double); ++i) { printf("%d\t", double_bytes.ftab[i]); } for(i = 0; i < sizeof(double); ++i) { double_bytes.ftab[i] = 0; } printf("\n%f\n", double_bytes.f); Ok,but how copy double into unsigned char vector?In your code initialize only the vector with 0 value.Maybe the problem is my english ;-)(my italian is worse).But: double any_float = 123.456;union {double f;unsigned char ftab[sizeof(double)];}double_bytes;double_bytes.f = any_float; initialize the vector double_bytes.ftab[] with any_float bytes, no ? --Pierre 这篇关于每字节读取一个双var字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-16 10:19