I want to convert a Java double (IEEE754 Double precision 64-bit) to it's binary representation, modify the 21 least significant bits to embed some metadata into the double, convert it back to a double, and maintain 6 decimal places of precision.
Constraint: The double values I will be dealing with will always be in the range of [-180, 180].
Example:
Double value: -145.88160204733163
IEEE754 Double precision 64-bit binary:
1100 0000 0110 0010 0011 1100 0011 0110 0001 0101 0111 1111 0010 1100 0000 1000
IEEE754 Double precision 64-bit binary with 21 least significant bits modified:
1100 0000 0110 0010 0011 1100 0011 0110 0001 0101 0110 0010 1001 1000 0110 0101
Double value with 21 least significant bits modified:
-145.88160199410336
I understand 1 bit needs to be maintained for the sign, 11 bits for the exponent, and 7 bits in the mantissa for the whole number between -180 and 180. Since I need to maintain 6 decimal places of precision, I thought an additional 24 bits for the significant figures would be sufficient to maintain 6 decimal places of precision (since 3.32 bits are required per digit, my understanding here might be incorrect) so I could use the 21 least significant bits to embed the metadata.
I'd like to know where I'm misunderstanding how 64-bit doubles are represented in binary and if there's any other way to modify the bits of a double without losing the required precision.
Any input is greatly appreciated!