Write a function to obtain a string with the binary representation of an integer
Réponses aux questions d'entretien
Utilisateur anonyme
28 févr. 2011
No one has handled the case for negative numbers.
We need to represent negative numbers in either 1s or 2s compliment
1
Utilisateur anonyme
8 févr. 2011
You need to do a reverse string at the end
Utilisateur anonyme
8 févr. 2011
static void bin_string(int n)
{
String bin = "";
int i = 0;
do
{
bin += (char)(((n) & 1) + 48);
n = n >> 1;
}
while (n != 0);
}
Utilisateur anonyme
19 janv. 2011
// it's caller's responsibility to delete the memory
char * conv_int_to_binary(int data)
{
int size = sizeof(data)*8;
char *binString = new char(size);
for ( int i = 0; i > i)&1;
}
return binString;
}