This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Range for Long Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Range for Long" Watch "Range for Long" New topic
Author

Range for Long

Fes D Gaur
Ranch Hand

Joined: Apr 29, 2005
Posts: 54
What is the range for long. I know long can hold 64 bits. Using the formula -2^bits-1 to (2^bits-1)-1 and using the calculator I calculate the range to be:
-9223372036854775808 to 9223372036854775808

But on compile it says that this is out of range. Could someone please give me the correct range for long and let me know what is wrong here.

Many thanks,
Fes D Gaur
Fes D Gaur
Ranch Hand

Joined: Apr 29, 2005
Posts: 54
Gadzooks! I figured it out. I have to have L after or l after the number. Then it works. I guess just like any floating point number is automatically assumed to be double and to change it to float an f or F is needed in the same way to take on a number larger than the integer range and to put it into a long type variable the L is needed at the end of the literal.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Range for Long
 
Similar Threads
How does a long fit in a float?
Easy question regarding long data types...
K&B ch-3 Ques-2
Clarification needed Shift Operator (Khalid Mughal-Old book)
asking question regarding string memory allocation in array