We were asked to make function that that converts Decimal numbers into Binary and takes an integer as an input but must give a string as an output. How do I store the array into one string?
string DecToBin(int num)
{
string res;
for (int n = 15; n >= 0; n--)
{
if ((num - pow(2, n)) >= 0)
{
res[n] = 1;
num -= pow(2, n);
}
else
{
res[n] = 0;
}
}
for (int n = 15; n >= 0; n--)
{
res[n];
}
}