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

JavaScript: Read 8 bytes to 64 bit integer

I have a buffer object which contains eight bytes. These eight bytes should now be interpreted as 64 bit integer. Currently I use following algorithm: var int = buff[0]; for (var i = 1; i < buff.length; i++) { int += (buff[i] * Math.pow(2, 8 *…
bodokaiser
  • 15,122
  • 22
  • 97
  • 140
5
votes
5 answers

The range of int in Java

I understand that the int range in Java should be -2^31 to 2^31-1. But when I run this code snippet with 20: public class Factorial { public int factorial(int n) { int fac=1; for (int i=1; i<=n; i++) { fac *= i; …
Boyang
  • 2,520
  • 5
  • 31
  • 49
5
votes
1 answer

Integer.parseInt() throws NumberFormatException with UTF-8 files

I need to parse integers from contents of a file. For testing my algorithms, when I give the contents of a file from a declared string String test = "15 kuruş"; Integer.parseInt works fine. But when I read with Scanner class from a UTF-8 file it…
Yunus Eren Güzel
  • 3,018
  • 11
  • 36
  • 63
5
votes
3 answers

C++ Class converting Object to Integer

I'm self learning C++ from a book (Schaums Programming with c++) and i've come across something i want to try but it doesn't cover(as fair as i can tell). I have a class that contains hrs:mins:secs. Is it possible to write a type conversion that…
binary101
  • 1,013
  • 3
  • 23
  • 34
5
votes
3 answers

What is the method in the API for converting between bases?

What is the method that you can use to convert between bases in Java? It is something like IntegerToBase (int, base), but I cannot remember.
user1755178
  • 255
  • 1
  • 4
  • 9
5
votes
3 answers

Why is 248x248 the maximum bi dimensional array size I can declare?

I have a program problem for which I would like to declare a 256x256 array in C. Unfortunately, I each time I try to even declare an array of that size (integers) and I run my program, it terminates unexpectedly. Any suggestions? I haven't tried…
user1843701
  • 51
  • 1
  • 3
5
votes
2 answers

accessing unsigned integer values in fortran

If I have a c_int8_t variable in Fortran and want to interpret the underlying bits as an unsigned integer (for indexing rather than for any arithmetic) what is the most efficient way to do the conversion? I want to do something like X(…
robince
  • 10,826
  • 3
  • 35
  • 48
5
votes
5 answers

Printing an integer in english

I am writing a code to display the digits of any positive integer in C language. For example, integer 345 would displayed as three four five. The code I wrote works fine for integers with all digits greater than 0. But certain integers like 10, 304,…
user1825355
  • 191
  • 1
  • 3
  • 11
5
votes
1 answer

from byteArray to bigInteger

how to convert a byteArray to bigInteger? it's important to say than my bytearray is not the ordinay byte[].. its a class in my project. basically i have an array of 256 bytes and i need to represent it as BigInteger in order to perform a…
5
votes
4 answers

Loop until integer input is in required range fails to work with non-digit character inputs

I'm having a problem with what should be incredibly simple code. I want to take in an integer between 1 and 3 with error checking. It works fine for checking for numbers that are too large or too small, but when a alpha/number combination is…
Rick_Sch
  • 456
  • 3
  • 10
  • 19
5
votes
4 answers

memory usage of ArrayList

I’m using ArrayList in my research project. I need to keep unknown number of integers in this list. Sometimes I need to update the list: remove existing records or add new records. As Integer is an object, it’s taking much more memory than…
user1539090
  • 75
  • 1
  • 6
5
votes
3 answers

JAVA: How to parse Integer numbers (delimited by a variable number of spaces) in a line of a text file

I want to parse numbers in a line of a text file line by line. For example, imagine _ as a space my text file content looks like: ___34_______45 _12___1000 ____4______167 ... I think you got the idea. Each line may have variable number of spaces…
Bob
  • 991
  • 8
  • 23
  • 40
5
votes
4 answers

What is the maximum integer value in Flex?

I was trying to display a number: 2893604342.00. But, when i am displaying it it is displayed as: -2893604342. Following is the code snippet ... avg += int(totalData[i][col.dataField]); I have even replaced it with Number, but it's still showing…
skumar
5
votes
3 answers

Minimum number of bits to represent number

What is the most efficient way to find out how many bits are needed to represent some random int number? For example number 30,000 is represented binary with 111010100110000 So it needs 15 bits
Marka
  • 377
  • 1
  • 4
  • 17
5
votes
4 answers

List of strings to integers while keeping a format in python

So what I want to do seems relatively simple, but for the life of me, I just can't quite get it. I have a .txt file like 4 2 6 5 1 9 4 5 And I want its information to be available to me like so (i.e. I do not need to write a new .txt file unless it…
Ason
  • 509
  • 2
  • 9
  • 25