long-integer

What is the modulo operator for longs in Java?

江枫思渺然 提交于 2020-01-11 04:32:06
问题 How do I find the modulo (%) of two long values in Java? My code says 'Integer number too large' followed by the number I'm trying to mod. I tried casting it to a long but it didn't work. Do I have to convert it to a BigInteger and use the remainder method? Thanks. 回答1: The % operator does work for longs. It sounds like you may have forgotten to stick L at the end of a numeric literal, as in 123456789L . Can we see your code? 回答2: You can only have an integer up to 2 147 483 647. If you want

Using the letter L in long variable declaration

隐身守侯 提交于 2020-01-10 03:57:25
问题 long l2 = 32; When I use the above statement, I don't get an error (I did not used l at the end), but when I use the below statement, I get this error: The literal 3244444444 of type int is out of range long l2 = 3244444444; If I use long l2 = 3244444444l; , then there's no error. What is the reason for this? Using l is not mandatory for long variables. 回答1: 3244444444 is interpreted as a literal integer but can't fit in a 32-bit int variable. It needs to be a literal long value , so it needs

How is 64-bit math accomplished on a 32-bit machine?

ぐ巨炮叔叔 提交于 2020-01-10 03:54:05
问题 If a 32-bit processor is, indeed, really only 32 bits in length, then how can math operations work on 64-bit numbers? For example: long lngTemp1 = 123456789123; long lngTemp2 = lngTemp1 * 123; According to MSDN, a long in C# is a signed 64-bit number: http://msdn.microsoft.com/en-us/library/ctetwysk(VS.71).aspx How is it that a 32-bit Intel Microprocessor can execute code, like the above without getting an overflow? 回答1: They use the carry bit for add and subtract. The assembler ops for "add

Java hex calculation

不问归期 提交于 2020-01-05 08:20:56
问题 I have the long value bits declared like so: long bits = len*8L; (304) System.out.println(bits); This outputs as 304 If I use the long name bits like so I get 0 & 0 respectively. System.out.println(bits>>(4*8)); System.out.println(0xFF&(bits>>(4*8))); If I use the actual number, like so, I get 304 and 48 respectively System.out.println(304>>(4*8)); System.out.println(0xFF&(304>>(4*8))); I'm trying to convert this Java to JavaScript but JavaScript gives me 304 and 48 in all scenarios. I need

Best practice solution for storing “unsigned long long” number in Realm

牧云@^-^@ 提交于 2020-01-05 06:37:05
问题 I have to store large numbers in Realm storage like 14000822124935161134 . Currently I store them by changing the type of them to string as follows and then save it: NSMutableDictionary *itemInsert = [item mutableCopy]; if([item valueForKey:@"timestamp"]) { unsigned long long timestamp = [[item valueForKey:@"timestamp"] unsignedLongLongValue]; [itemInsert setObject:[NSString stringWithFormat:@"%llu", timestamp] forKey:@"timestamp"]; } RLMRealm *realm = [RLMRealm defaultRealm]; [realm

How to return a long property as JSON string value with JAXB

巧了我就是萌 提交于 2020-01-04 04:11:12
问题 I have a Java class annotated with @XmlRootElement . This Java class has a long property ( private long id ) that I want to return to a JavaScript-client. I create the JSON as follows: MyEntity myInstance = new MyEntity("Benny Neugebauer", 2517564202727464120); StringWriter writer = new StringWriter(); JSONConfiguration config = JSONConfiguration.natural().build(); Class[] types = {MyEntity.class}; JSONJAXBContext context = new JSONJAXBContext(config, types); JSONMarshaller marshaller =

Java, Search for a long in a binary file input, 8 byte aligned, big endian

断了今生、忘了曾经 提交于 2020-01-04 03:18:09
问题 public static void main(String[] args) { File inFile = null; if (0 < args.length) { inFile = new File(args[0]); } BufferedInputStream bStream = null; try { int read; bStream = new BufferedInputStream(new FileInputStream(inFile)); while ((read = bStream.read()) > 0) { getMarker(read, bStream); System.out.println(read); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (bStream != null)bStream.close(); } catch (IOException ex) { ex.printStackTrace(); } } } private static

dynamically determine the type of integer based on the system (c++)

廉价感情. 提交于 2020-01-03 18:39:17
问题 I am writing a program to store data to a file on the unit of every 32 bits (i.e. 4 bytes at a time). I wrote the code in 64-bit windows system but the compiler I used is 32 bits (mingw32). In the current system, the size of int an long are the same, 32 bits (4bytes). I am current porting the code to other systems by recompiling with g++ (without changing the code). However, I found that the size of int or long are different and depending on the system. Is that any way (like using a macro in

Java for loop type long not supported [duplicate]

和自甴很熟 提交于 2020-01-03 06:39:14
问题 This question already has answers here : The literal xyz of type int is out of range (5 answers) Closed 5 years ago . I was trying to do some Project Euler question which involves pandigital numbers with special divisibility requirements of the first 5 prime numbers, and thought that this would be the starting point (see, 1023456789 is the first number being looked at, and 9876543210 is the last one). import java.util.*; public class pandigital_special { public static void main (String args[]

Kotlin parse Hex String to Long

♀尐吖头ヾ 提交于 2020-01-02 01:29:27
问题 I am starting to work in Kotlin and I need to parse a hex String to a long, which in java can be done with Long.parseLong("ED05265A", 16); I can not find anything this in Kotlin, although I can find val i = "2".toLong() This is not what I am looking for! before I write anything from scratch is there a built in function for this? 回答1: You can simply use java.lang.Long.parseLong("ED05265A", 16) Or import java.lang.Long.parseLong [...] parseLong("ED05265A", 16) Kotlin is compatible with Java,