Float to binary conversion I wrote a program to convert float to it's binary IEEE754 representation in C.
Any improvements to this is appreciated
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
void binary(float num) {
    int n = *(int *) &amp;num; //Evil bit hack from Quake3 Q_sqrt function
    int size = sizeof(n) * 8; 
    char *s = malloc(1 + size); //A string which can hold 32 characters
    s[size] = '\0';
    int index = size - 1;
    while(index &gt;= 0) {
        if (n &amp; 1)
            *(s + index) = '1';
        else
            *(s + index) = '0';
        n &gt;&gt;= 1;
        index--;
    }
    printf(&quot;%s\n&quot;, s);
    free(s);
}

int main(void) {
    float num;
    scanf(&quot;%f&quot;, &amp;num);
    binary(num);
}
IEEE754 conformance
Compilers aren't required to support IEEE754 decimals. Most implementations do, but regardless, it's better to check for maximum portability. If you're using C99 or later, the macro __STDC_IEC_559__ is defined whenever IEEE754 is supported.

sizeof(int)
Similarly, int isn't guaranteed to be 32 bits. The compiler only guarantees a minimum size of 16 bits. You can use the fixed width integer types defined in stdint.h i.e. uint32_t or int32_t.

Use size_t instead of int
The proper type for sizeof expression is size_t. As a general use, any variable representing size or index should be size_t.

Since you're not using s outside of the binary function, you can just allocate a fixed an array of size 33 on the stack instead of on the heap using malloc.
static const size_t num_bits = 33;
char s[num_bits];


*(s + index) is just fancy way to write s[index]. The latter is much cleaner, IMO and much more easier to understand for someone who isn't familiar with pointer arithmetic.