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

SQL Integer Range When Creating Tables

I'm trying to give my INT in one of my create statements a range of possible values, i.e. CREATE TABLE Site( **SiteID INT (1,4),** UserID INT UNSIGNED Not Null, Name varchar(128) Unique Not Null, Foreign Key (UserID) References…
Nick
  • 882
  • 2
  • 9
  • 31
5
votes
1 answer

Generating pseudo-random integers from a changing interval efficiently

I wrote the following class for generating random integers from a given interval [lower, upper]. class RandomInteger { protected: std::random_device randomDevice; std::default_random_engine randomEngine; …
clstaudt
  • 21,436
  • 45
  • 156
  • 239
5
votes
3 answers

Why can C++ functions create arrays of variable lengths?

According to this answer, which states: The compiler knows the size of the int type and therefore can generate the right assembler instruction that will reserve enough space on the stack in order to let foo live there. a compiler needs to know…
corazza
  • 31,222
  • 37
  • 115
  • 186
5
votes
2 answers

Input validation using scanf()

I have a program which accepts an integer from the user and uses this number in an addition operation. The code which I am using to accept the number is this: scanf("%d", &num); How can I validate the input such that if the user enters a letter or…
Matthew
  • 4,477
  • 21
  • 70
  • 93
5
votes
2 answers

How do I create an int array with randomly shuffled numbers in a given range

Basically, let's say I have an int array that can hold 10 numbers. Which mean I can store 0-9 in each of the index (each number only once). If I run the code below: int[] num = new int[10]; for(int i=0;i<10;i++){ num[i]=i; } my array would look…
user2129846
5
votes
2 answers

Randomly generate "-1" or "1" - Shortest Method

I need to randomly generate either a "-1" or a "1" to determine the sign of a number randomly... What's the shortest method? I am currently using this but it seems pretty long: sign = (round((arc4random() % 2)))-((round((arc4random() % 2))) == 0);
Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
5
votes
2 answers

SQL Server: Cast bool as integer

Why does the query: SELECT CAST((column LIKE '%string%') AS INT)+100 return Incorrect syntax near the keyword 'AS'
Mansoor
  • 285
  • 2
  • 8
  • 19
5
votes
2 answers

Integer factiorization function somewhere in Haskell library?

I find some library with implementation of integer factorization function. Preferably some fast implementation in some popular library, to not reinvent the wheel. Is there some ?
s9gf4ult
  • 862
  • 6
  • 20
5
votes
8 answers

How to convert last 4 bytes in an array to an integer?

If I have an Uint8Array array in JavaScript, how would I get the last four bytes and then convert that to an int? Using C# I would do something like this: int count = BitConverter.ToInt32(array, array.Length - 4); Is there an inequivalent way to do…
Joey Morani
  • 25,431
  • 32
  • 84
  • 131
5
votes
2 answers

Java 24-bit number signing

I'm currently doing some work that has me working with some 24-bit integers. Essentially I need to be able to get both the signed, and unsigned values from these 24-bits. Currently I'm using the following code to put the three bytes together and…
Tony
  • 3,587
  • 8
  • 44
  • 77
5
votes
1 answer

Assigning integers to strings

I'm working in Python and I have a list of integers: [1, 2, 1, 3, 2, 2, 1, 3]. I want to assign each integer a string as if it were a variable: ['red', 'orange', 'red', 'yellow', 'orange', 'orange', 'red', 'yellow']. How would I go about doing…
hayleyelisa
  • 359
  • 4
  • 5
  • 15
5
votes
4 answers

How to make JFormattedTextField accept integer without decimal point (comma)?

I used JFormattedTextField withNumberFormat in this way: -Creat a JFormattedTextField refernce JFormattedTextField integerField; -Create a NumberFormat refernce NumberFormat integerFieldFormatter; -In the constructor: integerFieldFormatter =…
Saleh Feek
  • 2,048
  • 8
  • 34
  • 56
5
votes
1 answer

Visualizing of frequency of integer data in R

When I try to visualize my integer data with histogram(mydata,breaks=c(0,n)), R usually doesnt care about how many breaks (usually 1 bar for each sample) do I use and it plots n-1 bars (first two bars are summed into one). In most cases I use…
user1991825
  • 309
  • 1
  • 5
  • 16
5
votes
1 answer

MATLAB: Reading both Bytes of a Unsigned 16-bit binary file

I have a binary Band Sequential (1-band, BSQ file), which is an unsigned 16-bit (2-byte) integer. Currently I'm reading the whole (image) through multibandread: img=multibandread('IMAGE.bsq',[400 400 1],'uint16',0,'bsq','n'); What process in MATLAB…
MBL
  • 1,197
  • 2
  • 11
  • 17
5
votes
3 answers

integer indexed with a string in c++

Possible Duplicate: In C arrays why is this true? a[5] == 5[a] How is it possible that this is valid C++? void main() { int x = 1["WTF?"]; } On VC++10 this compiles and in debug mode the value of x is 84 after the statement. What's going on?
ehremo
  • 387
  • 2
  • 8