3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jsメモ帳(ビット操作)

Last updated at Posted at 2014-06-25

find element in array

if (~[].indexOf("")) {}

javascript权威指南 中~运算符的解释
根据javascript中带符号的整数的表示方法,对一个值使用~运算符相当于改变它的符号并且减1.
所以~4=-5


##位运算豆知識##

  • 二进制的最高位是符号位,0表示正数,1表示负数。
  • 正数的原码,反码,补码都是本身
  • 负数的反码是符号位不变,其他位置由0变1,由1变0
  • 负数的补码=它的反码+1
  • 0的反码,补码均为0
  • 在计算机运算中,都是已补码的形式来运算的。

参考場所 【二进制】 原码 反码 补码 位移运算总结

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?