long-integer

How can i generate a long hash of a String?

时间秒杀一切 提交于 2019-11-30 03:48:46
问题 I have a java applciation in which I want to generate long ids for strings (in order to store those strings in neo4j). In order to avoid data duplication, I would like to generate an id for each string stored in a long integer, which should be unique for each string. How can I do that ? 回答1: long has 64 bits. A String of length 9 has 72 bits. from pigeon hole principle - you cannot get a unique hashing for 9 chars long strings to a long . If you still want a long hash: You can just take two

Convert from Long to date format

断了今生、忘了曾经 提交于 2019-11-30 03:01:00
I want to convert Long value to String or Date in this format dd/mm/YYYY. I have this value in Long format: 1343805819061. It is possible to convert it to Date format? AAnkit You can use below line of code to do this. Here timeInMilliSecond is long value. String dateString = new SimpleDateFormat("MM/dd/yyyy").format(new Date(TimeinMilliSeccond)); Or you can use below code too also. String longV = "1343805819061"; long millisecond = Long.parseLong(longV); // or you already have long value of date, use this instead of milliseconds variable. String dateString = DateFormat.format("MM/dd/yyyy", new

Why do C compilers specify long to be 32-bit and long long to be 64-bit?

北城余情 提交于 2019-11-30 02:57:15
问题 Wouldn't it have made more sense to make long 64-bit and reserve long long until 128-bit numbers become a reality? 回答1: Yes, it does make sense, but Microsoft had their own reasons for defining "long" as 32-bits. As far as I know, of all the mainstream systems right now, Windows is the only OS where "long" is 32-bits. On Unix and Linux, it's 64-bit. All compilers for Windows will compile "long" to 32-bits on Windows to maintain compatibility with Microsoft. For this reason, I avoid using "int

Cannot convert from type object to long

社会主义新天地 提交于 2019-11-30 00:59:15
问题 I have a hashtable named table . The type value is long . I am getting values using .values() . Now I want to access these values. Collection val = table.values(); Iterator itr = val.iterator(); long a = (long)itr.next(); But when I try to get it, it gives me error because I can't convert from type object to long . How can I go around it? 回答1: Try this: Long a = (Long)itr.next(); You end up with a Long object but with autoboxing you may use it almost like a primitive long. Another option is

Difference between Long.valueOf(java.lang.String) and new Long(java.lang.String)?

拜拜、爱过 提交于 2019-11-29 23:59:20
I'm consolidating code written by two different people and notice that casting a String value into a Long has been done in two different ways. Coder #1 has done this: String strId = "12345678"; ... Long lId = new Long(strId); While coder #2 has done this: String strId = "12345678"; ... Long lId = Long.valueOf(strId); Functionally, the code operates exactly the same. There's a try/catch block around each bit to handle any NumberFormatException that is thrown. The incoming string value is an 8 digit string that represents a decimal: "12345678" and in both cases it is correctly converted into

How to convert string to long [duplicate]

孤者浪人 提交于 2019-11-29 22:03:37
This question already has an answer here: How to convert String to long in Java? 8 answers how do you convert a string into a long. for int you int i = 3423; String str; str = str.valueOf(i); so how do you go the other way but with long. long lg; String Str = "1333073704000" lg = lg.valueOf(Str); This is a common way to do it: long l = Long.parseLong(str); There is also this method: Long.valueOf(str); Difference is that parseLong returns a primitive long while valueOf returns a new Long() object. The method for converting a string to a long is Long.parseLong . Modifying your example: String s

Is unsigned long int correct for this operation?

末鹿安然 提交于 2019-11-29 18:09:38
Here's my code: #include <stdio.h> int main(int argc, char *argv[]) { unsigned long int x = 0; // trying to make x = 2,147,483,648 x = 1 << 31; printf("%lu", x); } It's returning that x = 18446744071562067968. I read that unsigned long int should go up to 4,294,967,296, so why can't I use 1 << 32 to set x equal to 2,147,483,648? 1 << 31 causes undefined behaviour, if your system has 32-bit ints. The literal 1 is a signed int. You need to do an unsigned shift instead of a signed shift: x = 1UL << 31; I added L so that the code is still correct even on a 16-bit system, and it doesn't hurt to do

Scanner for long integer, Exception in thread “main” java.util.InputMismatchException

穿精又带淫゛_ 提交于 2019-11-29 18:07:06
I am at the last step to finalize my program, however whenever I enter my integer (long) I get a input mismatch: Compiler message: "Exception in thread "main" java.util.InputMismatchException: For input string: "4388576018402626" at java.util.Scanner.nextInt(Scanner.java:2097) at java.util.Scanner.nextInt(Scanner.java:2050) at CreditCardValidation.main(CreditCardValidation.java:12)" My code is as follows: import java.util.Scanner ; //import Scanner public class CreditCardValidation { public static void main (String[] args){ Scanner kbd = new Scanner(System.in) ; System.out.println("Please

How to get Windows window names with ctypes in python

烈酒焚心 提交于 2019-11-29 16:13:30
问题 I try to get Windows window title names and pids through handles with long objects. My code works but there is something wrong with it. I get only 4 window titles when I should get 10 or more. Can anyone help and tell me how to fix this code? I think the problem is with how I convert long objects (I don't understand them too well, as well as ctypes in general). from __future__ import print_function from ctypes import * psapi = windll.psapi titles = [] # get window title from pid def gwtfp():

Why in Scala Long cannot in initialized to null whear as Integer can

感情迁移 提交于 2019-11-29 14:45:04
问题 I am creating my Scala bean which is a configuration to be loaded from a YML config. I want a long property to be null if not specified, but I'm facing below issue. Any idea why? startOffset: Integer = null scala> var endOffset: Long = null <console>:11: error: an expression of type Null is ineligible for implicit conversion var endOffset: Long = null ^` PS: Yes I can use Option[Long] but wanted clarity and is there anything wrong with this approach. 回答1: Scala Long is literal date type like