Questions tagged [integer]

Common datatype in many programming languages for representing both negative and non-negative whole numbers. Use this tag for questions about using, storing, or manipulating integers. For 64-bit integers, use the [long-integer] tag instead.

An integer is a whole number that can be negative, positive, or zero. For example, -2, -1, 0, 1, 2. In many programming languages, the integer data type is commonly represented as 32-bits, but may also be 64-bits (Usually referred to as the Long data type).

For 32-bit integers:

  • The signed range is : -2147483648 to 2147483647.
  • The unsigned range is : 0 to 4294967295.

For 64-bit integers:

  • The signed range is : -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
  • The unsigned range is : 0 to 18,446,744,073,709,551,615.

For further reading, see the Wikipedia article on integers.

13448 questions
5
votes
3 answers

-9'223'372'036'854'775'808LL is unsigned

Since C++20 two's complement representation is the only representation allowed by the standard, with the guaranteed range from -2N-1 to +2N-1-1. So for a 64-bit signed integer type the range goes from -9'223'372'036'854'775'808 to…
user7769147
  • 1,559
  • 9
  • 15
5
votes
4 answers

Adding days to a DateTime in C#

Is it possible to add dates in C#? (DateTime.Today.ToLongDateString() + 10) I tried this but it doesn't work.
im useless
  • 7,151
  • 7
  • 35
  • 49
5
votes
2 answers

numeric type parse functions exception with negative numbers

System.out.println(Integer.parseInt("7FFFFFFF", 16)); //this is ok. System.out.println(Integer.parseInt("FFFFFFFF", 16)); //this throws Exception System.out.println(Integer.valueOf("FFFFFFFF", 16)); //this throws Exception When I try to convert…
User8500049
  • 410
  • 3
  • 12
5
votes
4 answers

Rescale a vector of integers

Assume that I have a vector, V, of positive integers. If the sum of the integers are larger than a positive integer N, I want to rescale the integers in V so that the sum is <= N. The elements in V must remain above zero. The length of V is…
Gurgeh
  • 2,130
  • 15
  • 28
5
votes
1 answer

Does the C++11 standard guarantee that the unary minus of a zero-valued signed integer is zero?

Does the C++11 standard guarantee that the unary minus of a zero-valued signed integer is zero? For example: int zero = 0; int n = -zero; int m = -0; assert(memcmp(&n, &zero, sizeof(int)) == 0); assert(memcmp(&m, &zero, sizeof(int)) == 0); I know…
Emile Cormier
  • 28,391
  • 15
  • 94
  • 122
5
votes
1 answer

Error with numpy array calculations using int dtype (it fails to cast dtype to 64 bit automatically when needed)

I'm encountering a problem with incorrect numpy calculations when the inputs to a calculation are a numpy array with a 32-bit integer data type, but the outputs include larger numbers that require 64-bit representation. Here's a minimal working…
SLhark
  • 177
  • 10
5
votes
1 answer

"Anomaly" in signed integer in C

I'm currently writing a lecture on ARM optimization, specifically on vector machines such as NEON as the final target. And since vector machines don't fare well with if-else slaloms, I'm trying to demonstrate how to get rid of them by bit-hacking. I…
Jake 'Alquimista' LEE
  • 6,197
  • 2
  • 17
  • 25
5
votes
3 answers

How to loop certain (variable) number of times?

This question may seem extremely basic, but I'm having a hard time figuring out how to do this. I have an integer, and I need to use a for loop to loop integer number of times. First, I tried - fn main() { let number = 10; // Any value is ok …
Lumin
  • 373
  • 6
  • 21
5
votes
1 answer

PostgreSQL: When casting an integer to a non-integer type to force floating point division in PostgreSQL, which number type should I use?

I know there are many integer division questions on StackOverflow, but I did not see this one. Similar to many programming languages, PostgreSQL performs integer division if both operands are integers. If one has: SELECT s.id AS student_id, …
5
votes
4 answers

How to preserve raster dataType in raster processing?

When doing raster math, for example raster1-raster2, the datatype of the output raster is 'FLT4S', even if the datatype ot both raster1 and raster 2 is 'INT2S'. How can I force the output to be 'INT2S', without writing to disk? Is there a global way…
Kristin
  • 51
  • 3
5
votes
6 answers

Java 8 primitive stream to collection mapping methods

Is there any significant difference (in performance or best practices) between those two stream creation methods? int[] arr2 = {1,2,3,4,5,6}; Arrays.stream(arr2) .map((in)->in*2) .mapToObj((in) -> new Integer(in)) …
Tomas
  • 3,269
  • 3
  • 29
  • 48
5
votes
2 answers

NumberFormatException error (parseInt)

Hopefully a very simple query, but it's left me scratching my head. I have a string, which is just a single integer, and I'm trying to then get that integer out as an int. This on the face of it shouldn't be a problem. // this is how I create the…
Alex
  • 2,000
  • 4
  • 23
  • 41
5
votes
2 answers

converting really large int to double, loss of precision on some computer

I'm currently learning inter-type data convertion in cpp. I have been taught that For a really large int, we can (for some computers) suffer a loss of precision when converting to double. But no reason was provided for the statement. Could…
Thor
  • 9,638
  • 15
  • 62
  • 137
5
votes
2 answers

Fastest way to calculate hash for Integer array without collision

The Java methods, Arrays.hashCode() or Objects.hash() return same hash for some Integer arrays with different content such as Integer[] a = {0,4,5,0} // hash 927520 Integer[] b = {0,3,36,0} // hash 927520 Same result is returned by the…
Maithilish
  • 965
  • 12
  • 21
5
votes
7 answers

How to join list of integers into one integer python

Given a list of hex integers, I want to end up with one hex integer where the integers are treated as most-significant first and least-significant last. For example, given... [0x1A, 0xF3, 0x74, 0xA3] ...I want to end up with 0x1AF374A3 In another…
Akash Sharma
  • 89
  • 3
  • 10