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
5 answers

How to add numbers and letters in a string in Python3.3.5 (The final result should be an int)?

My assignment is: "Write a function sumOfDigits that has one parameter of type string. The function should return the sum of the digits in the string. Do not treat multiple digit string as one number – “2014” should be treated as 4 different…
AndyM3
  • 183
  • 1
  • 4
  • 13
5
votes
1 answer

PHP array: integer index vs string index

Is there any difference between integer index and string index of PHP arrays (except of course the fact that the latter is called associative array)? So for example, what are the differences between the following two arrays: $intIndex[5] =…
CluelessNoob
  • 688
  • 1
  • 9
  • 20
5
votes
1 answer

How does Integer.toString() works internally?

I found that a similar question has been asked before here : how does Float.toString() and Integer.toString() works? But this doesn't speak about how that function internally works. When I opened the internally source code of Integer.toString(), it…
Saurabh Gokhale
  • 53,625
  • 36
  • 139
  • 164
5
votes
4 answers

Finding the index of an item in a list of lists

If I have this list of lists: [[1,2,3,4],[5,6,7,8,9,10],[11,12,13]] How might I be able to find the index of the sublist itself according to the value given? For example: If my value is 2, The index returned would be 0 If my value is 9, the index…
Peaser
  • 565
  • 3
  • 8
  • 16
5
votes
2 answers

TreeMap high-low key Integer sort

Map map = new TreeMap(); // Add Items to the TreeMap map.put(new Integer(8), "Eight"); map.put(new Integer(9), "Nine"); map.put(new Integer(1), "One"); map.put(new Integer(4), "Four"); …
user2803086
  • 153
  • 1
  • 3
  • 10
5
votes
4 answers

Haskell: Constrain function on type Double to only work with Integers

Suppose I'm writing a function that takes a list of integers and returns only those integers in the list that are less than 5.2. I might do something like this: belowThreshold = filter (< 5.2) Easy enough, right? But now I want to constrain this…
Derek Thurn
  • 14,953
  • 9
  • 42
  • 64
5
votes
3 answers

Is 00 an integer or octal in Java?

Is 00, 000, or 000... an integer in Java? Or is it an octal? If is it an octal is 001 or 0005 an octal?
stcho
  • 1,909
  • 3
  • 28
  • 45
5
votes
4 answers

C: Convert int array representing bits of a number into a single Int?

I am a beginner in C and wish to know how to convert an array of numbers that represent the bits of a number into the integer it represents. I searched online but only found char array to int. I am making converter and need to int array to toggle…
user3682308
  • 53
  • 1
  • 1
  • 6
5
votes
3 answers

Creating a Special Integer

I want to define a constant FOO in the namespace of Integer that is similar to Float::NAN in Float, which is itself an instance of Float. It will be used somewhat similar to symbols, i.e., to mark a special case (of an integer). I don't need it to…
sawa
  • 165,429
  • 45
  • 277
  • 381
5
votes
4 answers

Convert an integer into a signed string in Ruby

I have a report in which I'm listing total values and then changes in parentheses. E.g.: Songs: 45 (+10 from last week) So I want to print the integer 10 as "+10" and -10 as "-10" Right now I'm doing (song_change >= 0 ? '+' : '') +…
Tom Lehman
  • 85,973
  • 71
  • 200
  • 272
5
votes
1 answer

How can I fit a curve to a histogram distribution?

Someone asked me a question via e-mail about integer partitions the other day (as I had released a Perl module, Integer::Partition, to generate them), that I was unable to answer. Background: here are all the integer partitions of 7 (the sum of each…
dland
  • 4,319
  • 6
  • 36
  • 60
5
votes
4 answers

Evenly distributed integers within a range

Lets say I have a range between 0 and 100 and I want an array returned containing 3 integers which are evenly distributed within that range, what would be the best way to do this? For example: Range: 0-100 Wanted: 3 Returned: 25, 50, 75
DanCake
  • 2,003
  • 4
  • 23
  • 29
5
votes
2 answers

How to set up C++ Number Formatting to a certain precision?

I understand that you can use iomanip to set a precision flags for floats (e.g. have 2.0000 as opposed to 2.00). Is there a way possible to do this, for integers? I would like a hex number to display as 000e8a00 rather than just e8a00 or 00000000…
Anthony
  • 53
  • 2
5
votes
7 answers

How to get the value of Integer.MAX_VALUE in Java without using the Integer class

I have this question that has completely stumped me. I have to create a variable that equals Integer.MAX_VALUE... (in Java) // The answer must contain balanced parentesis public class Exercise{ public static void main(String [] arg){ [???] …
madsword19
  • 57
  • 1
  • 1
  • 3
5
votes
3 answers

BestPractice for conditions with strings and numbers

I just wonder how to write a number that has to be expressed as string. For instance: if (SelectedItem.Value == 0.ToString()) ... or if (SelectedItem.Value == "0") ... or public const string ZeroNumber = "0"; if (SelectedItem.Value ==…
Rookian
  • 19,841
  • 28
  • 110
  • 180