Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8644519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:18:50+00:00 2026-06-12T12:18:50+00:00

Why do I need to add an L letter to get the correct long

  • 0

Why do I need to add an “L” letter to get the correct long value? And what is the other value?

long oneYearWithL = 1000*60*60*24*365L;
long oneYearWithoutL = 1000*60*60*24*365;
System.out.println(oneYearWithL);//gives correct calculation result : 31536000000
System.out.println(oneYearWithoutL)//gives incorrect calculation result: 1471228928
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:18:51+00:00Added an answer on June 12, 2026 at 12:18 pm
    long oneYearWithL = 1000*60*60*24*365L;
    long oneYearWithoutL = 1000*60*60*24*365;
    

    Your first value is actually a long (Since 365L is a long, and 1000*60*60*24 is an integer, so the result of multiplying a long value with an integer value is a long value.

    But 2nd value is an integer (Since you are mulitplying an integer value with an integer value only. So the result will be a 32-bit integer. Now the result obtained for that multiplication is outside the actual range of integer. So, before getting assigned to the variable, it is truncated to fit into valid integer range.

    Take a look at the following print statement: –

    System.out.println(1000*60*60*24*365L);
    System.out.println(1000*60*60*24*365);
    System.out.println(Integer.MAX_VALUE);
    

    When you run the above code: –

    Output: –

    31536000000
    1471228928
    2147483647
    

    So, you can see the difference..

    011101010111101100010010110000000000 -- Binary equivalent of 1000*60*60*24*365L
        01111111111111111111111111111111 -- Binary equivalent of Integer.MAX_VALUE
    

    So, if you don’t add that L at the end of your number, the 4 most significant bit is removed from the first binary string..

    So, the string becomes..

    (0111)01010111101100010010110000000000 -- Remove the most significant bits..
          01010111101100010010110000000000 -- Binary equivalent of 1471228928
    

    (which you get as output)


    UPDATE: –
    From the above explanation, you can also understand that, even in the first assignment, if the result of your multiplication of integers before multiplying it with 365L goes out of range, then again it will be truncated to fit in integer range, or converted to 2's complement representation if required, and then only it will be multiplied with the long value - 365L.

    For e.g: –

    long thirtyYearWithL = 1000*60*60*24*30*365L;
    

    In the above example, consider the first part – 1000*60*60*24*30. The result of this multiplication is: – 2592000000. Now lets’ see how it is represented in binary equivalent: –

    2592000000 = 10011010011111101100100000000000  -- MSB is `1`, a negative value
                 01100101100000010011100000000001  -- 2's complement representation
    

    Decimal representation of the 2's complement representation is 1702967297. So, 2592000000 is converted to -1702967297, before getting multiplied to 365L. Now since, this value fits in the integer range which is : – [-2147483648 to 2147483647], so it will not be truncated further.

    So, the actual result will be: –

    long thirtyYearWithL = 1000*60*60*24*30*365L;
                         = 2592000000 * 365L;
                         = -1702967297 * 365L = -621583063040
    

    So, all these stuffs just considers the actual type of final result on applying the arithmetic operation. And this check is performed on each temporary result of operations moving from left to right(considering operators with left-to-right associativity). If any temporary result is found to be out of range, then that is converted accordingly to fit in the required range, before moving forward with next operation.


    UPDATE 2: –

    So, instead of: –

    long thirtyYearWithL = 1000*60*60*24*30*365L;
    

    if you move your 365L at the start, then you will get the correct result: –

    long thirtyYearWithL = 365L*1000*60*60*24*30; // will give you correct result
    

    Because, now your temporary result will be of type long, and is capable of holding that value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to get a string in jQuery to determine an integer value, then
I have a list of directory name and need to get the first letter
I need to add some validation that will only allow one capital letter in
I need add Auto complete on apex Tabular Form. there is a column as
I need add a new user group for mediawiki. The new group has more
I can't access a element with its href. Like this example, i need add
Hї! I have wrote test for my application. I need add item to database
Need to add two same name .csproj class libraries in my solution.Have two project
need to add a 2nd css stylesheet to a page. do i add a
I need to add recurring events with start time and end time. I used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.