I am trying to convert a float into a binary string. I've noticed a lot of tutorials out there are converting floats into what is called a "binary float." For example the number 8.5
is in binary float 1000.1
.
This is found by dividing the mantissa using the modf function to have the integer portion and the decimal portion as two separate integers. You then print the binary representation of both of these integers using bit manipulation or just by using division by 2 (for the decimal integer portion).
1000.1
is not what I want. I want the actual binary string representation.
01000001 00001000 00000000 00000000
I can't be assured that when using the modf function that my float will be able to translate into two integers.
I currently have function that will translate an integer into a binary string. I was wondering if something like this exists for floats. If so, please point me in the right direction. Thanks.