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

时间:2014-04-10 03:19:55

标签: java

此代码测试到底是什么?这是一个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 - Unsynchronisation Bit 7 in the 'ID3v2 flags' indicates whether or not unsynchronisation is used (see section 5 for details); a set bit indicates usage.

b - Extended header The 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 indicator The 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 个答案:

答案 0 :(得分:1)

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

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

0x0F是二进制的1111。 (这被称为"掩码"。)所以表达式说"如果在索引5的字节中设置了最低4位中的任何一个,则抛出异常"。