search

Home  >  Q&A  >  body text

java - & 0x7fff 是什么意思呢?

String strs = "13634393448";
Bytes.toBytes((short) (strs.hashCode() & 0x7fff));

这里面的 & 0x7fff 是什么意思呢?

PHPzPHPz2893 days ago1215

reply all(5)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 09:45:40

    0x07fff=0111111111111111
    What will happen if you do and operate this thing? The first bit is 0, and the other bits remain unchanged.

    Depending on the data type, the higher bit in the signed data type represents the symbol. In this case, the AND operation is used to obtain the absolute value, that is, to obtain the useful 15 bits.

    Sometimes bitwise search or bitwise operation is relatively faster.

    There is another situation where it is used to show off.

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:45:40

    String.hashCode()的返回值计算方式为:s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
    你给的13634393448,其hashCode结果是1002012672,也就是0x3bb98000
    0x7fff做""操作,也就是表示取0x3bb98000后三位的值,本题的结果自然就是0.

    reply
    0
  • PHPz

    PHPz2017-04-18 09:45:40

    0x7fff = 0111 1111 1111 1111
    & is an AND operation
    So this operation is to take the last 15 digits of the binary representation of the number "13634393448"

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:45:40

    0x Convert to hexadecimal

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:45:40

    A single & 是 按位与操作, 两个 & is the logical AND

    reply
    0
  • Cancelreply