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
1 answer

How to generate a a really big Random integer in Ruby?

I want to generate a 64 bit integer in ruby. I know in Java you have longs, but I am not sure how you would do that in Ruby. Also, how many charecters are in a 64 bit number? Here is an example of what I am talking about... 123456789999. @num =…
user2351234
  • 965
  • 2
  • 12
  • 20
5
votes
0 answers

Scipy fmin with integer solution

I need to minimize a function that only allows integer input. Can I solve it with scipy.optimize.fmin? Otherwise, is there any alternative?
Jorge Barata
  • 2,227
  • 1
  • 20
  • 26
5
votes
6 answers

How Java processes for overflow integers

Now signed_int max value is 2,147,483,647 i.e. 2^31 and 1 bit is sign bit, so when I run long a = 2,147,483,647 + 1; It gives a = -2,147,483,648 as answer.. This hold good. But, 24*60*60*1000*1000 = 86400000000 (actually)... In java,…
Gru
  • 2,686
  • 21
  • 29
5
votes
1 answer

Integer min and max values

I am a newbie in programming. I was studying from a Java object programming book and performing the tutorials and examples on the book simultaneously on computer. In the book it says that the maximum and minimum value of integers…
user1948951
5
votes
3 answers

MySQL integer unsigned arithmetic problems?

Does MySQL (5.0.45) like to do strange internal typecasts with unsigned maths? I am storing integers unsigned but when selecting basic arithmetic I get outrageous numbers: mysql> create table tt ( a integer unsigned , b integer unsigned , c float…
Jé Queue
  • 10,359
  • 13
  • 53
  • 61
5
votes
1 answer

Use of integers and doubles give different answers when they shouldn't

I'm solving a Project Euler Problem 14 using java. I am NOT asking for help solving the problem. I have already solved it, but I ran into something I can't figure out. The problem is like this: The following iterative sequence is defined for the…
Goatcat
  • 1,133
  • 2
  • 14
  • 31
5
votes
5 answers

().is_integer() not working

Whats wrong with this code: n = 10 ((n/3)).is_integer() I do not understand why I cannot set n = any number and check if it is an integer or not. Thanks for your help! python 2.7.4 error: Traceback (most recent call last): File…
aaaa
  • 265
  • 1
  • 4
  • 9
5
votes
3 answers

Counting Overlaps of Integer Ranges

I've been stumped on this algorithm for quite a bit. Say there are four ranges of integers. Each range has a Start and an End value. Range A: 0,5 Range B: 4,12 Range C: 2,10 Range D: 8,14 From these values I would like to get a new set which…
Sam Washburn
  • 1,817
  • 3
  • 25
  • 43
5
votes
1 answer

Integer to Bit in SQL

I have an Integer field, and I need to divide it into Bits to the SQL(Firebird). For each byte of the Integer field should be a new field. For Example: Integer field: 7 = 00000111 Bit 1 field1: 1 Bit 2 field2: 1 Bit 3 field3: 1 Bit 4 Field4:…
5
votes
5 answers

Put a 4 Byte Integer into the first 4 char elements of vector

I have a vector and want to put a 4 byte Integer into the first 4 elements. Is there a simpler way in C++ than masking like this: myVector.at(0) = myInt & 0x000000FF; myVector.at(1) = myInt & 0x0000FF00; myVector.at(2) = myInt &…
tzippy
  • 6,458
  • 30
  • 82
  • 151
5
votes
4 answers

Finding integer distance between two intervals

I'm looking for an easy way to find the minimum distance between two integer intervals using python. For example, the minimum between [0,10] and [12,20] would be 2. If the two intervals overlap in any way, the distance would be 0. Any suggestions…
David M
  • 710
  • 1
  • 8
  • 14
5
votes
5 answers

Algorithm speed with double and int?

how do algorithms with double compete compared to int values? Is there much difference, or is it neglectable? In my case, I have a canvas that uses Integers so far. But now as I'm implementing a scaling, I'm probably going to switch everything to…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
5
votes
3 answers

How to check std::string if its indeed an integer?

The following code converts an std::string to int and the problem lies with the fact that it cannot discern from a true integer or just a random string. Is there a systematic method for dealing with such a problem? #include #include…
pandoragami
  • 5,387
  • 15
  • 68
  • 116
5
votes
1 answer

Cannot seem to add two integers in javascript?

Im building John Conways game of life with HTML5 canvas. It has a gameOfLife object which contains an array with all the cells and their states (dead/alive). Here is the code that builds a cell: function cell(x,y){ this.x = x; this.y = y; …
styke
  • 2,116
  • 2
  • 23
  • 51
5
votes
2 answers

Sorting by integer value

I am writing a bash script and I am using ps -e -o %cpu command. I would like to have output of sorted %cpu values (descending). How to do that? I know that I should use sort command but I don't know how.
user1926550
  • 539
  • 5
  • 10
  • 18