辉县第一骚郭晓娟图片:二进制的11111100如何换算为十进制数,运算过程是怎样的?

来源:百度文库 编辑:中科新闻网 时间:2024/05/03 09:05:34
不好意思,此前问的那个打错了。
我在做一个SCJP的题。如下
After execution of the following code, what is the value of a?
byte a;
byte b = 3; // binary 00000011
byte c = -3;
if (~b > c)
{
a = c;
}
else
{
a = b;
}
但答案说是3
其解析为:
B is correct. "~" is the bitwise inverter. Hence the binary representation of ~b is "11111100" which is -4, thus the "else" condition gets executed and a gets the value of b which is 3.
就是不知道怎么会是负数了。

二进制的11111100如何换算为十进制数是252。
  具体过程的基本规律是从右往左依次乘以2的位数幂,即为:
  0*2^0+0*2^1+1*2^2+1*2^3+1*2^4+1*2^5+1*2^6+1*2^7+1*2^8
  =0+0+4+8+16+32+64+128
  =252

你怎么不会想啊,我刚告诉你方法了啊

11 11 11 00
76 54 32 10

0*2~0=0
0*2~1=0
1*2~2=4
1*2~3=8
1*2~4=16
1*2~5=32
1*2~6=64
1*2~7=128

0+0+4+8+16+32+64+128=252

0位就是2的0次幂
1位就是2的1次幂
依次类推
有就加没有就不加
2的8次幂+2的7次幂+2的6次幂+2的5次幂+2的4次幂+2的3次幂+2的2次幂
就是111111100的十进制数了

用电脑中的计算器(附件中),查看中有标准型和科学型,选科学型,再选二进制,输入11111100,再选十进制

11111100
2^7+2^6+2^5+2^4+2^3+2^2 数1后有几位就2的几次方 再家起来就是了