java - & 0x7fff 是什么意思呢?
PHPz
PHPz 2017-04-18 09:43:40
0
5
1128

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

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

PHPz
PHPz

学习是最好的投资!

reply all(5)
巴扎黑

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.

刘奇

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

PHPzhong

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"

伊谢尔伦

0x Convert to hexadecimal

巴扎黑

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template