向大侠们求解.
public class Example4 {
public static void main(String args[]){
double db = 123.923d;
float f = (float)db;
long l = (long)db;
int i = (int)db;
short s = (short)db;
byte b = (byte)db;
System.out.print("d = " + db + "; f = " + f + "; l = " + l);
System.out.print("; i = " + i + "; s = " + s + "; b = " + b);
db = 5127.87d;
b = (byte)db;
System.out.print("; d = " + db + "; b = " + b);
//为啥b等于7呢?
}
}
为啥输出后b的结果是7呢?
[解决办法]
db先转换成int,5127;
二进制为1010000000111;
强转成Byte,取低八位,0000111;
十进制就是7.