public double decodeDouble(boolean implicit) throws Asn1Exception {
        long intValue;

        //
        // There must be at least 2 bytes available
        //
        if (residualLength < 2)
            throw new Asn1Exception("Attempt to read past end of stream");

        //
        // Validate the tag for an explicit value
        //
        if (!implicit && stream[next] != ASN1_DOUBLE)
            throw new Asn1Exception("Field at offset "+next+" is not a DOUBLE");

        if ((stream[next]&ASN1_CONSTRUCTED) != 0)
            throw new Asn1Exception("DOUBLE must not be a constructed field");

        next++;
        residualLength--;

        //
        // Decode the field length
        //
        int length = decodeLength();

        if (length > 8)
            throw new Asn1Exception("Value length "+length+" is not valid");

        if (length > residualLength)
            throw new Asn1Exception("Attempt to read past end of stream");

        //
        // Decode the double value
        //
        if (stream[next] >= 0)
            intValue = 0;
        else
            intValue = -1;

        for (int i=0; i<length; i++)
            intValue = (intValue<<8)|((int)stream[next++]&0xff);

        residualLength -= length;

        return Double.longBitsToDouble(intValue);
    }