long-integer

Multiplying int with long result c#

喜你入骨 提交于 2019-11-30 22:57:05
Wonder why. C# .Net 3.5 int a = 256 * 1024 * 1024; int b = 8; long c = b * a; Console.WriteLine(c);//<-- result is -2147483648 Where does this minus from? Where does this minus from? From the integer overflow. Note that your code is equivalent to: int a = 256 * 1024 * 1024; int b = 8; int tmp = b * a; long c = tmp; Console.WriteLine(c); I've separated out the multiplication from the assignment to the long variable to emphasize that they really are separate operations - the multiplication is performed using Int32 arithmetic, because both operands are Int32 - the fact that the result is assigned

Unsigned arithmetic and integer overflow

拟墨画扇 提交于 2019-11-30 20:26:25
问题 I am trying to understand arithmetic overflow. Suppose I have the following, unsigned long long x; unsigned int y, z; x = y*z; y*z can lead to an integer overflow. Does casting one of the operands to an unsigned long long alleviate this issue. What is the expected result of the multiplication of a 64-bit operand with a 32-bit operand? 回答1: unsigned long long x; unsigned int y, z; x = y*z; The evaluation of the expression y*z is not affected by the context in which it appears. It multiplies

Fortran: handling integer values of size: ~700000000000

爱⌒轻易说出口 提交于 2019-11-30 20:02:39
Currently I'm brushing up on my Fortran95 knowledge (don't ask why)... I'm running in to a problem though. How does one handle large integers, eg. the size of: ~700000000000 INTEGER(KIND=3) cannot hold this number. If anyone is interested the compiler I have available is Silverfrost FTN95. I am using the integer to run through a larger set of data. Do you have any suggestions? The standard solution (since Fortran 95, so I assume your compiler supports it) is to use the SELECTED_INT_KIND intrinsic to probe for valid integer kinds (whose values are compiler dependent) and the HUGE intrinsic.

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

此生再无相见时 提交于 2019-11-30 18:41:32
Wouldn't it have made more sense to make long 64-bit and reserve long long until 128-bit numbers become a reality? 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" and "long". Occasionally I'll use "int" for error codes and booleans (in C), but I never use them for any

Multiplying int with long result c#

拟墨画扇 提交于 2019-11-30 17:28:02
问题 Wonder why. C# .Net 3.5 int a = 256 * 1024 * 1024; int b = 8; long c = b * a; Console.WriteLine(c);//<-- result is -2147483648 Where does this minus from? 回答1: Where does this minus from? From the integer overflow. Note that your code is equivalent to: int a = 256 * 1024 * 1024; int b = 8; int tmp = b * a; long c = tmp; Console.WriteLine(c); I've separated out the multiplication from the assignment to the long variable to emphasize that they really are separate operations - the multiplication

Cannot convert from type object to long

纵饮孤独 提交于 2019-11-30 17:23:04
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? 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 to use Generics: Iterator<Long> itr = val.iterator(); Long a = itr.next(); Number class can be used for to

Double from long bits

元气小坏坏 提交于 2019-11-30 15:19:03
I have an unsigned long long (or uint64_t ) value and want to convert it to a double . The double shall have the same bit pattern as the long value. This way I can set the bits of the double "by hand". unsigned long long bits = 1ULL; double result = /* some magic here */ bits; I am looking for a way to do this. The portable way to do this is with memcpy (you may also be able to conditionally do it with reinterpret_cast or a union, but those aren't certain to be portable because they violate the letter of the strict-alias rules): // First, static assert that the sizes are the same memcpy(

java short,integer,long performance

霸气de小男生 提交于 2019-11-30 14:46:11
问题 I read that JVM stores internally short, integer and long as 4 bytes. I read it from an article from the year 2000, so I don't know how true it is now. For the newer JVMs, is there any performance gain in using short over integer/long? And did that part of the implementation has changed since 2000? Thanks 回答1: long 64 –9,223,372,036,854,775,808 to 9 ,223,372,036,854,775,807 int 32 –2,147,483,648 to 2,147,483,647 short 16 –32,768 to 32,767 byte 8 –128 to 127 Use what you need, I would think

How do I split up a long value (32 bits) into four char variables (8bits) using C?

北城余情 提交于 2019-11-30 13:19:38
问题 I have a 32 bit long variable, CurrentPosition, that I want to split up into 4, 8bit characters. How would I do that most efficiently in C? I am working with an 8bit MCU, 8051 architectecture. unsigned long CurrentPosition = 7654321; unsigned char CP1 = 0; unsigned char CP2 = 0; unsigned char CP3 = 0; unsigned char CP4 = 0; // What do I do next? Should I just reference the starting address of CurrentPosition with a pointer and then add 8 two that address four times? It is little Endian. ALSO

java short,integer,long performance

谁说我不能喝 提交于 2019-11-30 12:00:54
I read that JVM stores internally short, integer and long as 4 bytes. I read it from an article from the year 2000, so I don't know how true it is now. For the newer JVMs, is there any performance gain in using short over integer/long? And did that part of the implementation has changed since 2000? Thanks JonH long 64 –9,223,372,036,854,775,808 to 9 ,223,372,036,854,775,807 int 32 –2,147,483,648 to 2,147,483,647 short 16 –32,768 to 32,767 byte 8 –128 to 127 Use what you need, I would think shorts are rarely used due to the small range and it is in big-endian format. Any performance gain would