G
Guest
Should the following algorithm produce the binary equivalent of an inputed
decimal value?
----------
cout << "Decimal value: ";
cin >> Decimal;
Binary = 0;
Remainder = Decimal;
for(Power = 4; Power = -1; Power--) {
Remainder = Decimal - (pow(2,Power));
if(Remainder < 0) {
Binary = Binary * 10;
Remainder = Decimal;
}
if(Remainder >=0) {
Binary = ((Binary * 10) + 1);
Decimal = Remainder;
}
}
cout << "Binary value: " << Binary << "\n";
system("Pause");
break;
----------
Can anyone suggest any other methods that does not implement built-in
functions?
Please and thankyou.
decimal value?
----------
cout << "Decimal value: ";
cin >> Decimal;
Binary = 0;
Remainder = Decimal;
for(Power = 4; Power = -1; Power--) {
Remainder = Decimal - (pow(2,Power));
if(Remainder < 0) {
Binary = Binary * 10;
Remainder = Decimal;
}
if(Remainder >=0) {
Binary = ((Binary * 10) + 1);
Decimal = Remainder;
}
}
cout << "Binary value: " << Binary << "\n";
system("Pause");
break;
----------
Can anyone suggest any other methods that does not implement built-in
functions?
Please and thankyou.