Do not include leading 0's in binary strings

This commit is contained in:
Justin Ethier 2016-08-19 00:45:56 -04:00
parent 5c75f550fd
commit 218902038f

View file

@ -1373,13 +1373,23 @@ object Cyc_length(void *data, object l)
char *int_to_binary(char *b, int x)
{
b[0] = '\0';
int z;
for (z = 65536; z > 0; z >>= 1) {
strcat(b, ((x & z) == z) ? "1" : "0");
unsigned int i = 0x80000000, leading_zeros = 1;
if (x == 0) {
*b++ = '0';
*b = '\0';
return b;
}
while (i){
if (x & i) {
*b++ = '1';
leading_zeros = 0;
} else if (!leading_zeros) {
*b++ = '0';
}
i >>= 1;
}
*b = '\0';
return b;
}