Question: need help on convert -42 to binary in c++ what do I need to add here to make it work with an unassign integer. #include

need help on convert -42 to binary in c++

what do I need to add here to make it work with an unassign integer.

#include

using namespace std;

void decToBinary(int n)

{

unsigned int binaryNum[255];

int i = 0;

while (n > 0)

{

binaryNum[i] = n % 2;

n = n / 2;

i++;

}

for (int j = i - 1; j >= 0; j--)

cout << binaryNum[j];

}

int main()

{

int n = 42;

decToBinary(n);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!