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
4
votes
3 answers

Negatives in underscore.js: why is _isEqual(0, -1 * 0) returning false?

Using the javascript library underscore.js (v.1.3.1), I've reproduced the following on the mac in up-to-date Chrome (17.0.963.56) and in Firefox 7.0: 0 === -1 * 0 > true _.isEqual(0, -1 * 0) > false This is surprising, at least to me. I expected…
brahn
  • 12,096
  • 11
  • 39
  • 49
4
votes
3 answers

Catching an Integer Overflow in a recursive function [C]

UPDATE: Thank you for the helpful comments and advice. Using what you guys said, this is what I've come up with: #include ... else { int a = binom(n - 1, k - 1); int b = binom(n - 1, k); if(a > 0) { if (b >…
Milan Patel
  • 53
  • 1
  • 1
  • 5
4
votes
2 answers

what is the fastest way to count the number of matching digits in base 4?

Given two unsigned integers, what is the fastest way to count the number of matching digits in their base 4 representation? example 1: A= 13 = (31) in base 4 B= 15 = (33) in base 4 the number of matching digits in base 4 is 1. example 2: A= 163 =…
mghandi
  • 275
  • 1
  • 9
4
votes
2 answers

Finding the first number larger than N that is a relative prime to M

Basically, the title says everything. The numbers are not too big (the maximum for N is ~2/3 * max(long) and max M is max(long)), so I think even a simple solution that I currently have is sufficient. M is always bigger than N. What I currently…
Klark
  • 8,162
  • 3
  • 37
  • 61
4
votes
3 answers

C++: Convert unsigned long long int into vector and vice versa

Can anyone tell me how to convert unsigned long long int into vector and vice versa. For converting from unsigned long long int to vector, I tried the following: unsigned long long int x; vector buf(sizeof(x)); memcpy( &buf[0], &x, sizeof( x )…
veda
  • 6,416
  • 15
  • 58
  • 78
4
votes
5 answers

Python custom sorting, by the difference in two elements of a tuple

I'm new to Python's custom sorting capabilities, but I'm sure the following can be done. I have a list of tuples, and each tuple looks like this: (some_int, some_int2, string) I want to sort the list by the descending difference between some_int…
MitchellSalad
  • 4,171
  • 8
  • 23
  • 24
4
votes
5 answers

Do the Java Integer and Double objects have unnecessary overhead?

I am working with Java 1.3, so it does not support generics. I came up with a shady work around. I want to know if the Integer and Double objects have an unnecessary overhead; I guess what I am asking is: do Integers take up same amount of space as…
Davidthefat
  • 63
  • 1
  • 8
4
votes
2 answers

Unsigned comparison of numbers in Clojure?

I'm attempting to write an image processing library in Clojure, but I've run into a problem while writing my tests. The image data is stored as a 2D array of integers, which are signed (Java, and by extension Clojure, doesn't have unsigned…
Joel
  • 1,437
  • 2
  • 18
  • 28
4
votes
6 answers

go beyond Integer.MAX_VALUE constraints in Java

Setting aside the heap's capacity, are there ways to go beyond Integer.MAX_VALUE constraints in Java? Examples are: Collections limit themselves to Integer.MAX_VALUE. StringBuilder / StringBuffer limit themselves to Integer.MAX_VALUE.
setzamora
  • 3,560
  • 6
  • 34
  • 48
4
votes
6 answers

Java Integer.parseInt() Not Working for Large Numbers

I have the following simple piece of code which is intended to detect that a given IPv4 address indeed only has numeric values (that is after the dots have been stripped): import edu.gcc.processing.exceptions.net.IPAddressNumericException; //Get…
Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195
4
votes
5 answers

Extracting Multiple Integers from a string in Javascript

I'm trying to set up my page so a user is able to type in a string like "25a89ss15s9 8 63" and it alerts the user "25, 89, 15, 9, 8, 63" and then further alerts the user "8, 9, 15, 25, 63, 89". So I'm trying to separate the integers from the string…
Josh Hayden
  • 43
  • 1
  • 3
4
votes
6 answers

What's the correct way to test if a variable is a number in PHP?

When I fetch data from a database, the result is a string even if it has an number value. Here's what I mean: // An integer $int=10; if(is_int($int)) // Returns true ... // A string $int='10'; if(is_int($int)) // Returns false ... I want both of…
Leo Jiang
  • 24,497
  • 49
  • 154
  • 284
4
votes
1 answer

Numerical types beyond cstdint

I've been using types from cstdint (such as uint32_t) in my code regularly, but now they don't quite fit my needs, particularly with regards to templates. Is there a way to specify an integer type that is twice the size of a template argument? When…
David Stone
  • 26,872
  • 14
  • 68
  • 84
4
votes
4 answers

How to get list of decimal numbers "hidden" in binary number in PHP?

firstly, I very much apologize for my poorly written title of this question. So please someone with native English, change the title appropriately. My question is rather simple, it follows: I am using integer to store multiple types of one item. For…
Frodik
  • 14,986
  • 23
  • 90
  • 141
4
votes
5 answers

Appending List Elements in R

I have two large, ordered lists of integers. I would like the integer length at [i]position of hello to be equal to the length at [i] position of bye. Here is a simplified reproducible example to simulate my dataset : c1<- c(0,1,0,1,1,1,0,0) |>…
AR459
  • 63
  • 3
1 2 3
99
100