| Author |
how is 1 second represent as a 'long'
|
Harold Barnes
Greenhorn
Joined: May 04, 2005
Posts: 6
|
|
|
how is 1 second represent as a 'long'? Is is 000000001000?
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24045
|
|
|
Several methods in classes in Java deal in millisecond times. One second is 1000 milliseconds, yes. To write 1000 as a long literal, you could write 1000L; but in most cases just 1000 would do, as the int will be converted to a long as needed.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Ryan McGuire
Ranch Hand
Joined: Feb 18, 2005
Posts: 944
|
|
Originally posted by Harold Barnes: how is 1 second represent as a 'long'? Is is 000000001000?
Another issue: An integer or long literal that starts with a '0' is interpreted to be in octal. So 1000 = 1000(base 10) but 01000 = 1000(base 8) = 512(base 10). IF I UNDERSTAND CORRECTLY, including that many zeros doesn't make the compiler use a long. It would look at 000000001000, recognize it as 512(base 10) and use a regular int. If you want a long, use Ernest's suggestion of a trailing 'L'. (You could use a trailing lowercase 'l', but that looks too much like a one for my comfort. ) Ryan
|
 |
 |
|
|
subject: how is 1 second represent as a 'long'
|
|
|