读书人

doubleToASCII如何实现

发布时间: 2013-03-16 11:51:46 作者: rapoo

doubleToASCII怎么实现
c++中怎么实现一个double类型的数,转换为ASCII,存放在BYTE数组中?请教大虾们啦!
[解决办法]
转换为ASCII?这。。。
你可以放到单字节char的数组里,需要读取的时候再按8字节读取一个double就行.
聪明点的话,弄个联合
[解决办法]
楼主是想取到double的内存组织形式么??那你直接用memcpy把数据拷贝出来就可以了啊。double是IEEE754标准形式。不是ASSIC形式存储的
[解决办法]
直接写个函数,把double的二进制位表示按十六进制显示出来


template<typename T>
void show_bytes(T& x)
{
byte_pointer start = (byte_pointer)&x;
for(int i=0;i<sizeof(T);i++) //显示每个字节里的数据
{
printf(" %.2x",start[i]);
}
}

[解决办法]
%a
double
Signed hexadecimal double precision floating point value having the form [?]0xh.hhhh p±dd, where h.hhhh are the hex digits (using lower case letters) of the mantissa, and dd are one or more digits for the exponent. The precision specifies the number of digits after the point.

%A
double
Signed hexadecimal double precision floating point value having the form [?]0Xh.hhhh P±dd, where h.hhhh are the hex digits (using capital letters) of the mantissa, and dd are one or more digits for the exponent. The precision specifies the number of digits after the point.

读书人网 >C++

热点推荐