public boolean decodeBoolean(boolean implicit) throws Asn1Exception {
        boolean retValue;

        //
        // 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_BOOLEAN)
            throw new Asn1Exception("Field at offset "+next+" is not a BOOLEAN");

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

        next++;
        residualLength--;

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

        if (length != 1)
            throw new Asn1Exception("Value length "+length+" is not valid");

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

        //
        // Any non-zero value is TRUE while a zero value is FALSE
        //
        retValue = (stream[next]!=0 ? true : false);
        next++;
        residualLength--;
        return retValue;
    }