java - How to get value of byte that belongs to out of range? -


{double = 295.04; int b = 300;  byte c = (byte) a;  byte d = (byte) b;  system.out.println(c +" " + d);} 

storage size of byte 8 bits , maximum positive byte value 127.so c isn't equal 300.then tried convert 300 binary number.the binary number(of 300) has 9 bits.i confused value of c , d . why c = 39 , d = 44 ?

byte signed primitive datatype in java. when assign bigger byte value, cycle.

suppose entered 300 in byte variable. after first cycle byte variable filed 0,127 means 128 place // 300-128 = 172

after second cycle byte variable filed 0,127 means 128 place // 172-128 = 44

now in third cycle 44. hope answer query.


Comments