Given a floating point number, write a function to count set bits in its binary representation.
We can use the idea discussed here. The idea is to take address of the given floating point number in a pointer variable, typecast the pointer to char * type and process individual bytes one by one. We can easily count set bits in a char using the techniques discussed here.
Following is C implementation of the above idea.
Binary representation of 0.156250 has 6 set bits
This article is contrbuted by Vineet Gupta. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above