I'm having trouble figuring out how to convert a decimal such as 4.050 to binary, octal, and hex.
I'm familiar using modulus, but since you can't use modulus with floats, I'm lost...
Heres what I got while using int, this program converts to binary.
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
int num;
int total = 0;
cout << "Please enter a decimal: ";
cin >> num;
while(num > 0)
{
num /= 2;
total = num % 2;
cout << total << " ";
}
return 0;
}
if you want convert float like 0.34 to hex
0.34 * 16 = 5.44
convert 5 to hex(.5)
0.44 * 16 = 7.04(.7)
if you stop by here, the answer would be .57
you could stop the program until the fractional number reach zero or
stop when the precision is enough for you