快叫我java小菜鸟 2019-11-25 10:13 采纳率: 100%
浏览 4819

apache Base64源码最后validateCharacter方法为什么会&上补0的个数?

/**
     * <p>
     * Validates whether the character is possible in the context of the set of possible base 64 values.
     * </p>
     *
     * @param numBits number of least significant bits to check
     * @param context the context to be used
     *
     * @throws IllegalArgumentException if the bits being checked contain any non-zero value
     */
    private long validateCharacter(final int numBitsToDrop, final Context context) {
        i**f ((context.ibitWorkArea & numBitsToDrop) != 0)** {
        throw new IllegalArgumentException(
            "Last encoded character (before the paddings if any) is a valid base 64 alphabet but not a possible value");
        }
        return context.ibitWorkArea >> numBitsToDrop;
    }

我很疑惑的地方是:验证结尾两个或四个比特为0,不应该是&3 或者 &15吗?详细的代码不再贴了,有能解惑的大神先行拜谢了。

问题解决参见:问题解决结果

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-11-25 12:40
    关注

    numBitsToDrop
    顾名思义,这个参数的意思是需要丢弃的位数

    评论

报告相同问题?