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

What is the size of integer in 8-bit, 16-bit, 32-bit processors/microcontrollers?

What is the size of integer in 8-bit, 16-bit, 32-bit processors/microcontrollers ? I guess it depends on the internal accumulator/register size. But not sure. Thanks
Kiran
  • 51
  • 1
  • 1
  • 2
5
votes
4 answers

Format integer to string with 5 digits

I need to have a string, based on an integer, which should always have 5 digits. Example: myInteger = 999 formatedInteger = "00999" What is the best way of doing this in classic ASP?
RSilva
  • 6,753
  • 11
  • 43
  • 49
5
votes
3 answers

Compiler Error: Invalid Conversion from int* to unsigned int* [-fpermissive]

I'm having the strangest issue today. I was working with an example online, and to my lack of surprise, it didn't work (they pretty much never do). I went about fixing it myself, but I seem to be stuck on this error: Error: Invalid Conversion from…
Boom
  • 2,465
  • 4
  • 19
  • 21
5
votes
2 answers

Generating Unique ID Number from Two Integers

Given 2 integers a and b (positive or negative). Is there any formula / method for generating unique ID number? note: 1. result from f(a,b) and f(b,a) should be different. 2. calculating f(a,b) for x times (x > 1), the result should be same. To make…
stranger
  • 189
  • 1
  • 3
  • 15
5
votes
2 answers

Web API 2 does not process PATCH requests for Integers

I'm having a problem with Web API 2 (.net 4.5.1) in that it seems to ignore PATCH requests where the property is an integer, but processes other types without a problem (I've tested string and decimal). I’ve setup an unsecured test API with a…
Martin Kearn
  • 2,313
  • 1
  • 21
  • 35
5
votes
4 answers

How to represent a triangle of integers?

This addresses "a specific programming problem" from On-Topic I am working on an interview question from Amazon Software Interview The question is " Given a triangle of integers, find the path of the largest sum without skipping. " My question is…
committedandroider
  • 8,711
  • 14
  • 71
  • 126
5
votes
2 answers

Python TypeError: an integer is required while working with Sockets

Research: Getting a "TypeError: an integer is required" in my script https://github.com/faucamp/python-gsmmodem/issues/39 https://docs.python.org/2/howto/sockets.html Here is my complete error output: Traceback (most recent call last): File…
mee
  • 489
  • 5
  • 11
  • 19
5
votes
2 answers

How to clear int[] array in android?

I have an example that calculates total expense and income. There are some values in integer array that converted from a string array. Once I am running the code the sum is 6000 and running again the same code the sum gets multiplied to 12000. How…
Reshmin
  • 95
  • 1
  • 5
  • 17
5
votes
6 answers

How to find multiples of the same integer in an arraylist?

My problem is as follows. I have an arraylist of integers. The arraylist contains 5 ints e.g[5,5,3,3,9] or perhaps [2,2,2,2,7]. Many of the arraylists have duplicate values and i'm unsure how to count how many of each of the values exist. The…
Julio
  • 6,182
  • 11
  • 53
  • 65
5
votes
3 answers

unsigned tinyint in php?

I'm working on a class to manipulate html hex color codes in php. Internally, the class treats RGB values as decimals. When I'm adding or subtracting, I never want the value to exceed 255 nor 'subceed' zero. If course, I can do something piecemeal…
user151841
  • 17,377
  • 29
  • 109
  • 171
5
votes
5 answers

Is pointer just an integer?

If I know the address of an data object, could I store the address as an integer and operate the integer as a pointer? For example, void main(){ long a = 101010; long *p = &a; long b = p; printf("%lld\n", *(long*)b); } Is it always…
Min Fu
  • 789
  • 1
  • 6
  • 16
5
votes
5 answers

how to convert byte value into int in objective-c

Please tell me how to convert bytes to NSInteger/int in objective-c in iPhone programming?
suse
  • 10,503
  • 23
  • 79
  • 113
5
votes
4 answers

How to generate a matrix with random integer elements between -3 and 3, but not 0 in MATLAB

To generate a random matrix, I have used the following: x = randi([-3,3],4) However I don't want any zeros in my output matrix. How can I do this?
newzad
  • 706
  • 1
  • 14
  • 29
5
votes
3 answers

Fastest way to calculate an X-bit bitmask?

I have been trying to solve this problem for a while, but couldn't with just integer arithmetic and bitwise operators. However, I think its possible and it should be fairly easy. What am I missing? The problem: to get an integer value of arbitrary…
Daniel A.A. Pelsmaeker
  • 47,471
  • 20
  • 111
  • 157
5
votes
1 answer

How does the last integer promotion rule ever get applied in C?

6.3.1.8p1: Otherwise, the integer promotions are performed on both operands. Then the following rules are applied to the promoted operands: If both operands have the same type, then no further conversion is needed. Otherwise, if both operands…
SiegeX
  • 135,741
  • 24
  • 144
  • 154