gpt4 book ai didi

java - if ((bytes[FLAGS_OFFSET] & 0x0F) != 0) 抛出新的

转载 作者:行者123 更新时间:2023-12-01 13:09:41 27 4
gpt4 key购买 nike

这段代码测试到底是为了什么?它用于 ID3 标记库。我最近才开始学习“安定”。据我所知,“&0x0F”将这些位移至右侧。

如果您能对此 if 语句提供任何说明,我们将不胜感激。

protected static final int FLAGS_OFFSET = 5;
if ((bytes[FLAGS_OFFSET] & 0x0F) != 0) throw new UnsupportedTagException("Unrecognised bits in header");

第 5 个字节包含一个标志:

ID3v2 flags             %abc00000

"%x is used to indicate a bit with unknown content."

a - UnsynchronisationBit 7 in the 'ID3v2 flags' indicates whether or not unsynchronisation is used (see section 5 for details); a set bit indicates usage.

b - Extended headerThe second bit (bit 6) indicates whether or not the header is followed by an extended header. The extended header is described in section 3.2.

c - Experimental indicatorThe third bit (bit 5) should be used as an 'experimental indicator'. This flag should always be set when the tag is in an experimental stage.

最佳答案

如果两个操作数的该位都设置为 1,则 & 结果中的某位为 1,例如:

  01010101& 00001111==========  00000101

0x0F 在二进制中是 1111。 (这称为“掩码”。)因此该表达式表示“如果在索引 5 处的字节中设置了任何最低 4 位,则抛出异常”。

关于java - if ((bytes[FLAGS_OFFSET] & 0x0F) != 0) 抛出新的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22978034/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com