public static void main (String[] ses) {
System.out.println(740 * (24 * 60 * 60 * 1000));
}
tried it on google, it gave a different result also on a scientific calculator.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because the result is 63,936,000,000 which is more than you can store in a Java integer (which by default those are because none of them are prefaced with L). An integer can only store 4 bytes (32 bits) and that number would require 36 bits. It then overflows, essentially only using the final (first?) 32 bits of the result. Because the first (last? depends on how you look at it) of these bits determines if a number is signed or not, when the number is again actually treated like an integer, it is displayed as negative.
This is particularly useful for calculating hashes, as the only logical alternative I see is to make all numbers over the max value equal to the max value, which I think we can agree is a poor choice.
If you made it
System.out.println(740L * (24 * 60 * 60 * 1000));it should use a long which can store much larger numbers.You’ll note I have question marks through this – bytes are bytes, and bits are bits. What really matters is how you interpret them. There is contention in the software development community what it really means to be the first digit, bit, or byte. Consider “1234” as a number. Is 1 the first digit? Most common folk would agree it is, because it’s written first when we look at it. But others would consider 4 to be the first digit, because it’s convenient to do so for calculation purposes. (Consider adding – where do you add first? Wouldn’t that be the first number?)
So that’s why I appear to be indecisive as I say first/last – I just want to make it clear what’s going on.