Because both float (32-bit) and double (64-bit) follow the exact same IEEE 754 architecture, converting a float to a double is purely a matter of shifting, re-biasing, and padding the bit fields.

Part 1: How to Convert a Float to a Double at the Bit Level

To promote a 32-bit float into a 64-bit double without losing meaning, you map its three components (, , ) into the larger 64-bit container:

  1. Sign Bit (): Copied directly (1 bit stays 1 bit).
  2. Exponent ():
    • A float uses a bias of .
    • A double uses a bias of .
    • To convert, you extract the true exponent (), add the new double bias (), and place it into the 11-bit double exponent field:
  3. Mantissa ():
    • The float has 23 bits of precision. The double has 52 bits.
    • You copy the 23 bits into the most significant 23 bits of the double’s mantissa, and pad the remaining 29 lower bits with zeros. (You don’t gain extra precision, you just fit it into the larger layout).

Java Implementation Example

public class FloatToDoubleBits {
    public static void main(String[] args) {
        float f = 5.5f;
        
        // 1. Get the raw 32-bit integer representation of the float
        int floatBits = Float.floatToIntBits(f);
        
        // 2. Extract components
        long sign = (floatBits >>> 31) & 0x1L;
        long expFloat = (floatBits >>> 23) & 0xFFL;
        long mantissaFloat = floatBits & 0x7FFFFFL;
        
        // 3. Re-bias exponent for double (subtract 127, add 1023)
        long expDouble = expFloat - 127 + 1023;
        
        // 4. Shift mantissa from 23-bit space to 52-bit space (shift left by 29)
        long mantissaDouble = mantissaFloat << (52 - 23);
        
        // 5. Pack into 64-bit double bits
        long doubleBits = (sign << 63) | (expDouble << 52) | mantissaDouble;
        double convertedDouble = Double.longBitsToDouble(doubleBits);
        
        System.out.println("Converted Double: " + convertedDouble); // Output: 5.5
    }
}