• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how is 1 second represent as a 'long'

 
Harold Barnes
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how is 1 second represent as a 'long'? Is is 000000001000?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ryan McGuire
Ranch Hand
Posts: 1078
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic