i have this function
// Print binary representation of ints
#include <iostream>
using namespace std;
void main() {
int n;
while (cin >> n) {
cout << "decimal: " << n << endl;
// print binary with leading zeros
cout << "binary : ";
for (int i=31; i>=0; i--) {
int bit = ((n >> i) & 1)
cout << bit;
}
cout << endl;
}//end loop
}
i need to modify this function in this way :
instead of display the result of the conversion on the screen i would like to make a function that accepts two parameters
Dec2Bin(int DecToConvert, int LenghtOfConversion)
and returns the binary number with the specified LengthOfConversion.
(eg an Array of char ,length: LengthOfConversion)
thank you
// Print binary representation of ints
#include <iostream>
using namespace std;
void main() {
int n;
while (cin >> n) {
cout << "decimal: " << n << endl;
// print binary with leading zeros
cout << "binary : ";
for (int i=31; i>=0; i--) {
int bit = ((n >> i) & 1)
cout << bit;
}
cout << endl;
}//end loop
}
i need to modify this function in this way :
instead of display the result of the conversion on the screen i would like to make a function that accepts two parameters
Dec2Bin(int DecToConvert, int LenghtOfConversion)
and returns the binary number with the specified LengthOfConversion.
(eg an Array of char ,length: LengthOfConversion)
thank you