美文网首页
Math.abs(~10)

Math.abs(~10)

作者: 这很重要吗 | 来源:发表于2017-06-14 19:59 被阅读0次

以Math.abs(~10)为例
10在计算机中是32位的,所以10的二进制是
00000000 00000000 00000000 00001010
~10在计算机中是10取反码,为
11111111 11111111 11111111 11110101 ,符号位为1所以~10是负数,
因为负数在计算机中是以正值的补码存在,正值的补码是
正值是:10再取反就是~10,取反符号为是不变的:
10000000 00000000 00000000 00001010 正值求出来后,求补码,+1即可
所以是10000000 00000000 00000000 00001011,所以就是-11,
所以Math.abs(~10)=Math.abs(-11),所以为11
同理Math.abs(~2018)=Math.abs(-2019),所以为2019

由此我们可以看出规律:“~x”的结果为“-(x+1)”
所以“~2018”就等于“-2019”,Math.abs(-2019)即2019!!

相关文章

  • Math.abs(~10)

    以Math.abs(~10)为例10在计算机中是32位的,所以10的二进制是00000000 00000000 0...

  • math.对象

    console.log(Math.abs(10)); // 绝对值 console.log(Math.pow(2,...

  • 数值

    数值 // absolute 绝对值Math.abs(5);Math.abs(-5); // 5 // round...

  • Math

    Math 相关方法(小函数):Math.random(); //0-1随机数Math.abs(10); //绝对值...

  • 负数时间戳转换为正确的时间

    var a = '-280000000'if(a<0) a = Math.abs(a)

  • Math

    1.绝对值 Math.abs();

  • JS数值

    整型浮点型科学计数法十六进制 复杂运算 绝对值 Math.abs(5);Math.abs(-5); 四舍五入-把浮...

  • java常识

    1、求绝对值:Math.abs(data);

  • Math.abs(-2147483648)

    Math.abs(-2147483648)输出为-2147483648https://www.zhihu.com/...

  • JS中的几种数学方法

    //alert(Math.abs(-9)); // 绝对值 //alert(Math.ceil(2.6)) ;...

网友评论

      本文标题:Math.abs(~10)

      本文链接:https://www.haomeiwen.com/subject/jseeqxtx.html