// - 2^7 ~ 2^7-1;
byte a = Byte.MAX_VALUE;
byte b = Byte.MAX_VALUE;
// - 2^15 ~ 2^15-1
short s1 = Short.MIN_VALUE;
short s2 = Short.MAX_VALUE;
// - 2^31 ~ 2^31-1
int i1 = Integer.MIN_VALUE;
int i2 = Integer.MAX_VALUE;
// - 2^63 ~ 2^63-1
long h1 = Long.MIN_VALUE;
long h2 = Long.MAX_VALUE;
byte aa = (byte) (new BigInteger("2").pow(7).longValue()); //-128 - as expected
short bb = (short) (new BigInteger("2").pow(15).longValue()); //-32768 - as expected
int cc = (int) new BigInteger("2").pow(31).longValue(); //-2147483648 - as expected
long dd = new BigInteger("2").pow(63).longValue(); //-9223372036854775808 - as expected
System.out.println(aa);
System.out.println(bb);
System.out.println(cc);
System.out.println(dd);
aa = (byte) (new BigInteger("2").pow(7).longValue() - 1); //127 - as expected
bb = (short) (new BigInteger("2").pow(15).longValue() - 1); //32767 - as expected
cc = (int) (new BigInteger("2").pow(31).longValue() - 1); //2147483647 - as expected
dd = (new BigInteger("2").pow(63).longValue() - 1); //9223372036854775807 - as expected
System.out.println(aa);
System.out.println(bb);
System.out.println(cc);
System.out.println(dd);
댓글