I have the next code which tries to convert a double type number into its binary form. I know the algorithm, the integer part of the number can be converted to binary the same way an int type number would, and the remainig fractionary part can be converted this way:
integerPart = (int)value; fractionaryPart = value-integerPart; while(fractionaryPart != 0.0) { fractionaryPart = fractionaryPart*2; integerPart = (int)fractionaryPart; fractionaryPart = fractionaryPart - integerPart; } this is the code to convert the integer part
bits = 64 //8 bytes char binary[] = new char[bits]; for(i = bits-1;i >= 0;i--) { if((integerPart&1) == 1) binary[i] = '1'; else if((integerPart&1) == 0) binary[i] = '0'; integerPart >>= 1; } the problem is that I have to print the entire number the way a double number would look into the RAM memory (an 8 bytes format) for example if I have the number 42.375, the result must be 101010.011. But I don´t know how to combine the binary numbers of the while() and the for() and put them into an array of 64 bits, like:
|00000000|00000000|00000000|00000000|00000000|00000000|00000010|1010.011|
any suggestions??
