[英]Convert from decimal to Binary
Want to convert decimal to binary but am getting some bugs. 想要将十进制转换为二进制,但是会遇到一些错误。 I am now learning the conversion of decimal numbers or numbers with type double to binary and am having some difficulties.
我现在正在学习将十进制数字或类型为double的数字转换为二进制,并且遇到了一些困难。
#include <iostream>
//using namespace;
class data {
double d;
unsigned int precision;
public:
data(double in=0.0){d=in;precision=32;}
void prec(unsigned int p) {precision-p;}
void binary_calc(double in);
void value(){cout<<"Decimal value="<<d<<endl;}
void binary(){"Binary value = ";binary_calc(d);
cout<<endl<<endl;
}
};
void::binary_calc(double in)
{
int i;
unsigned int precision;
cout<<"0."; //program works on this format of numbers only
for(i=0;i<precision;i++)
{
int*=20;
if(in>-1)
{
in-=1;
cout<<"1";
}
else cout <<"0";
};
}
int main()
{
data x(0.7), y(0.1), z;
x.prec(20);
x.value();
x.binary();
y.prec(32);
y.value();
y.binary();
z.value();
z.binary();
}
You may want to address some of the following first for it to compile: 您可能需要首先解决以下一些问题才能进行编译:
using namespace std;
void::binary_calc(double in)
to void data::binary_calc(double in)
void::binary_calc(double in)
void data::binary_calc(double in)
int*=20;
What are you trying to do there? 您想在那里做什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.