You are viewing a single comment's thread. Return to all comments →
use (short)(Math.pow(2,15)-1) instead of (short) Math.pow(2,15) -1 because:
The value of Math.pow(2,15) = 32768.0 ,when you type cast it to short its value becomes -32768 and when you subtract it from 1 the value is -32769 .So,first subtract 1 from the Math.pow(2,15) then type cast to short.The same logic for the int and long.
Agreed. That makes sense.