long-integer

convert from long long to int and the other way back in c++

自古美人都是妖i 提交于 2019-12-20 09:38:07
问题 How to convert from long long to int and the other way back in c++ ?? also what are the properties of long long , especially its maximum size, thank in advance .. 回答1: Type long long is typically 64 bits. Type int is likely to be 32 bits, but not on all machines. If you cast an int to a long long, you can do my_long_long = (long long) my_int and it will be just fine. If you go the other direction, like my_int = (int) my_long_long and the int is smaller than 64-bits, it won't be able to hold

Fibonacci calculation in Java Longs shows up negative

帅比萌擦擦* 提交于 2019-12-20 07:47:35
问题 My Fibonacci calculator works fine, but when going up to higher numbers the result comes up negative, as it would if it was an Integer over its max value. It is working with a cache java.util.Map<Integer, Long> . Everything that goes into the Map is exactly what is expected, but when printing it out I get e.g. for 291: -784134397488903422 According to http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibCalcX.html, it should be:

Java - Error on: long n = 8751475143;

ε祈祈猫儿з 提交于 2019-12-20 07:29:37
问题 This number falls into the long range, so why do I get the error: Exception in thread "main" java.lang.Error: Unresolved compilation problem: The literal 8751475143 of type int is out of range 回答1: Make it long n = 8751475143L; L will make it long literal by default its int An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int (§4.2.1). The suffix L is preferred, because the letter l (ell) is often hard to distinguish from the

Java convert double to date format

十年热恋 提交于 2019-12-20 05:38:21
问题 I have made a little app in ios+firebase, now I am trying to connect android. In ios I save date as double (for example: -242528463.775282), but then I trying to retrieve same double in java it giving me another date. in IOS - 01.07.2009 in Java - 29.12.1969 double myDouble = date; long myLong = (long) (myDouble); System.out.println(myLong); Date itemDate = new Date(itemLong); String myDateStr = new SimpleDateFormat("dd-MM-yyyy").format(itemDate); editTextDate.setText(myDateStr); Is it

Java Long Compare and ValueOf method undefined

佐手、 提交于 2019-12-20 04:26:09
问题 I am referencing my java version JDK 1.8 but I am still getting error. What is wrong with this referencing (writing Java after 6 years)? or any other simpler way to do this? I did some search and these functions are available in later java versions. Eclipse is Oxygen The method valueOf(Long) is undefined for the type Long The method compareTo() is undefined for the type Long import java.util.Comparator; import java.lang.Long; public class MyComparator<Long> implements Comparator<Long>{

Java long assignment confusing

老子叫甜甜 提交于 2019-12-20 04:04:09
问题 Why does this java code long a4 = 1L; long a3 = 1; long a2 = 100L * 1024 * 1024 * 1024; long a1 = 100 * 1024 * 1024 * 1024; System.out.println(a4); System.out.println(a3); System.out.println(a2); System.out.println(a1); when run, output 1 1 107374182400 0 instead of the expected 1 1 107374182400 107374182400 output? 回答1: 107374182400 is exactly 25 times the full range of an integer (2^32) , which means that if you try to fit it into an integer it will overflow. And because it would fit

Java long assignment confusing

允我心安 提交于 2019-12-20 04:04:09
问题 Why does this java code long a4 = 1L; long a3 = 1; long a2 = 100L * 1024 * 1024 * 1024; long a1 = 100 * 1024 * 1024 * 1024; System.out.println(a4); System.out.println(a3); System.out.println(a2); System.out.println(a1); when run, output 1 1 107374182400 0 instead of the expected 1 1 107374182400 107374182400 output? 回答1: 107374182400 is exactly 25 times the full range of an integer (2^32) , which means that if you try to fit it into an integer it will overflow. And because it would fit

double to long without conversion in Java

假如想象 提交于 2019-12-19 07:25:29
问题 I need to turn double into long preserving its binary structure, not number value. Just change type, but leave binary value as it is. Is there a native way to do it? 回答1: There is Double with to doubleToLongBits and doubleToLongRawBits. Javadoc is your friend. 来源: https://stackoverflow.com/questions/15065869/double-to-long-without-conversion-in-java

double to long without conversion in Java

好久不见. 提交于 2019-12-19 07:25:11
问题 I need to turn double into long preserving its binary structure, not number value. Just change type, but leave binary value as it is. Is there a native way to do it? 回答1: There is Double with to doubleToLongBits and doubleToLongRawBits. Javadoc is your friend. 来源: https://stackoverflow.com/questions/15065869/double-to-long-without-conversion-in-java

What does 'Natural Size' really mean in C++?

China☆狼群 提交于 2019-12-19 06:45:11
问题 I understand that the 'natural size' is the width of integer that is processed most efficiently by a particular hardware. When using short in an array or in arithmetic operations, the short integer must first be converted into int . Q: What exactly determines this 'natural size'? I am not looking for simple answers such as If it has a 32-bit architecture, it's natural size is 32-bit I want to understand why this is most efficient, and why a short must be converted before doing arithmetic