long-integer

The literal xyz of type int is out of range

99封情书 提交于 2019-12-17 02:31:41
问题 I am working with data types at the moment in Java, and if I have understood correctly the type long accepts a value between the ranges of: -9,223,372,036,854 to +9,223,372,036,854,775,807. Now as you can see below I have create a Long variable called testLong , although when I insert 9223372036854775807 as the value, I get an error stating: "The literal 9223372036854775807 of the type int is out of range." I don't know why it is referring to the long data type as an int Anyone have any ideas

Converting Long to Date in Java returns 1970

爷,独闯天下 提交于 2019-12-17 02:22:14
问题 I have list with long values (for example: 1220227200, 1220832000, 1221436800...) which I downloaded from web service. I must convert it to Dates. Unfortunately this way, for example: Date d = new Date(1220227200); returns 1 Jan 1970. Anyone know another way to convert it correctly? 回答1: The Date constructor (click the link!) accepts the time as long in milliseconds , not seconds. You need to multiply it by 1000 and make sure that you supply it as long . Date d = new Date(1220227200L * 1000);

How Do I Get Extra From an Intent (as a type Long)?

╄→гoц情女王★ 提交于 2019-12-14 02:43:25
问题 I have this problem accessing an extra from an intent. The value i'm parsing is a long type, and I need this value to be stored in a database. So this is what I have so far: MainActivity: package com.example.calendar; import java.sql.Date; import java.util.Calendar; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.CalendarView; import static

Checking if long is in array

▼魔方 西西 提交于 2019-12-14 02:14:35
问题 I need to make sure that a certain long value isn't in an array. But for some reason, this isn't working... !d.toString().contains(sq.toString()); I am sure I am getting something really backwards... but I can't figure out what! 回答1: Try !Arrays.asList(d).contains(sq); 回答2: Look at the static methods in java.util.Arrays. Your array will need to be sorted for the binarySearch() to work. 来源: https://stackoverflow.com/questions/5010044/checking-if-long-is-in-array

Get a long value from an NSString

那年仲夏 提交于 2019-12-14 01:54:21
问题 I need to get a long value from an NSString . For example, I have this: NSString *test = @"5437128"; and I need : long myLong = 5437128; How I can get this long value from the NSString ? Thank you, it will help me! 回答1: Use the NSScanner like in the following code: unsigned x; [[NSScanner scannerWithString: s2] scanHexInt: &x]; when typing the scanHexInt stop at scan and see yourself which one you need - there are many possibilities to get values from strings.... You might want to use

How to compare values stored in List<Long> with a long value?

老子叫甜甜 提交于 2019-12-13 22:00:17
问题 I'm retrieving some long values and storing it in List<Long> l . Here is the logged out value of List<Long> l : D/lng: [2197, -1007, 4003] Then, I'm trying to compare it with long values like <=900 or >900 . Here's how: public void filterRequests(final List<Long> l) { final int size = l.size(); int i; for (i = 0; i < size; i++){ } Log.d("lng", String.valueOf(l)); if (l.get(i) <= 900) { // do the logic when l <= 900 } else { } } The problem is that if (l.get(i) <= 900) or if (l.get(i) > 900)

Java / Android - Calculate difference between timestamps [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-13 15:39:23
问题 This question already has answers here : How to format a duration in java? (e.g format H:MM:SS) (17 answers) Closed 2 years ago . I have a problem figuring out how to calculate the elapsed time between two timestamps (hours, minutes, seconds). This is the result: String starttime = beginElement.getTimestamp(); String endtime = element.getTimestamp(); I/Start time: 1496258892612 I/End time: 1496258928999 long diffTime = Long.parseLong(endtime) - Long.parseLong(starttime); I/Diff time: 36387

Casting an int into a long

妖精的绣舞 提交于 2019-12-13 13:57:49
问题 I have a question regarding the conversion from int into long in java. Why for floats there is no problem: float f = (float)45.45;//compiles no issue. float f = 45.45f; //compiles no issue. However for the long type it seems to be a problem: long l = (long)12213213213; //with L or l at the end it will work though. long l = (long)12213213213L; It seems that once the compiler notify an error due to an out-of-range issue it blocks there without checking for any possible casting that the

Why does 1ul << 64 return 1 instead of 0? [duplicate]

穿精又带淫゛_ 提交于 2019-12-13 10:52:00
问题 This question already has answers here : Unexpected output when executing left-shift by 32 bits (2 answers) GCC left shift overflow (4 answers) Closed 3 years ago . Consider the following piece of code: // Simply loop over until 64 is hit. unsigned long x = 0; for (int i = 0; i <= 64; i++) { if (i == 64) { x = 1ul << i; printf("x: %d\n", x); } } We know that unsigned long is 64-bit wide, and left shifting 1 by 64 positions would become 1000...000 (64 zeros behind one), and would have been

Why does this not result in 1000? [duplicate]

99封情书 提交于 2019-12-13 09:48:02
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Java problem-Whats the reason behind and what will be probable output long milli=24*60*60*1000; long micro=24*60*60*1000*1000; long result=micro/milli; The result should be 1000 but its not. Why does it work when I use 24*60*60*1000*1000L ? Can someone tell me the reason for this? 回答1: The trouble is that the calculation is done on int s and then casted to long , and unfortunately 24*60*60*1000*1000 won't fit in