本文介绍了十进制小数到二进制数的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一个将我实际拥有的小数部分转换为二进制变量的函数.
谁能帮我这个忙...
I''m looking for a function which convert the decimal fraction i have in real, to a binary var.
Can anyone please help me on this one...
推荐答案
void printFloat(float a)
{
unsigned long* temp = (unsigned long*)&a;
unsigned long one = 1;
for(int i = 31; i >= 0; i--)
{
if(((*temp) & (one << i)) == 0)
cout << "0";
else cout << "1";
if (i % 4 == 0)
cout << " ";
}
cout << endl;
}
我不确定这是否是您所需要的.希望对您有所帮助.
I''m not sure if this is what you need. Hope it helps.
这篇关于十进制小数到二进制数的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!