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

Euclidean integer modulo in C++

Where can I find an implementation or library that computes the remainder of an integer Euclidean division, 0 <= r < |n|?
NaomiJO
  • 313
  • 1
  • 3
  • 13
5
votes
2 answers

Error handling using integers as input

Ive set up this program that checks the mark out of 100 for a test. If the user inputs less than 60 it should say fail if more than 59, pass. mark = int(input("Please enter the exam mark out of 100 ")) if mark < 60: print("\nFail") elif mark <…
Tech484
  • 51
  • 1
  • 1
  • 2
5
votes
1 answer

Address substraction value is alway 12? Is size of variables slight?

I'm currently playing with C, C++ and ASM. I can see that there's always difference of 12 between ebp substraction values. My disassembled code: Code: int main() { int abc = 10; int def = 20; short int a = 1; long int b = 1000; …
user35443
  • 6,309
  • 12
  • 52
  • 75
5
votes
1 answer

Calculate the smallest integer with k bits set that is greater than another integer x?

I want to calculate the smallest integer with exactly k bits set, that is greater than another integer x. For example if x = 1001010 then for k=2, the answer should be 1010000 for k=4, the answer should be 1001011 and for k=5 the answer is 1001111…
adi
  • 580
  • 2
  • 12
5
votes
2 answers

manually printing a N-byte integer

What is a scalable algorithm to print an N-binary-digit integer manually whose value does not fit in long long. I know printf and friends, along with (which most likely piggy-backs on have this builtin for standard types, but I'd…
rubenvb
  • 74,642
  • 33
  • 187
  • 332
5
votes
2 answers

Java int array to StringBuilder

How to convert int array with UTF-8 string to StringBuilder in a while loop? For example: int array: 71, 73, 70, 56, 57, 97, 149, 0, 55, 0, 247... resulting string: GIF89a• €÷€ € €€ÀÜÀ¦Êð*?ª*?ÿ... The line contains Latin, Cyrillic and Asian…
Dmitriy
  • 161
  • 2
  • 12
5
votes
2 answers

Objective-C: Returning int to BOOL method

I am new to Objective-C and i wonder why this method compiles, can anyone explain me why? Thank you -(BOOL) isEnabled{ return 56; }
Zillan
  • 720
  • 7
  • 15
5
votes
5 answers

Finding the maximum of two integers in binary using bit logic only

This is a bit tricky, it's a nice challenge for those up to the task I think. And I did search through all the questions previously asked, but I couldn't find what I want. The aim here is, given 2 integers written in binary on n bits, to find the…
Charles
  • 988
  • 1
  • 11
  • 28
5
votes
2 answers

java: writing integers to file as unsigned 8 bit integer

In java, how do I write integers to a file so that they are unsigned 8 bit integers (within range 0 to 255) ? Is it enough that the numbers are of type int and within 0-255, or do I need to convert them to some other type first? I think it's just…
Joel Feodiyoup
  • 53
  • 1
  • 1
  • 3
5
votes
2 answers

Convert long to int, keep positive/negative/0

I want to implement a java.util.Comparator with Long: new Comparator() { public int compare(Long l1, Long l2) { // (*) } } I have a solution with operator ?:: return l1==l2 ? 0 : (l1>l2 ? 1 : -1); But I wonder if there is any…
Freewind
  • 193,756
  • 157
  • 432
  • 708
5
votes
1 answer

Opengl Geometry shader integer texture fetch fails

I'm trying to sample an integer texture from my geometry shader running on a GeForce 330m. It seems to return other values than I load into the texture. I use this code (basically) for creating and loading the texture: glGenTextures( 1, &textureId…
dascandy
  • 7,184
  • 1
  • 29
  • 50
5
votes
3 answers

Str Function in VBA for Excel adds a character to the string

I am converting an integer to string using the str() function However, I noticed that the str() function would return an extra character to the string. For example, MsgBox(Len(str(1))) would return 2. What is the extra character being appended?
Steveng
  • 1,451
  • 4
  • 15
  • 14
4
votes
5 answers

C# - Correct validation for integers

I am currently building my project using windows forms and came across a minor "problem". I have the user enter an hour which is stored as an int. I want to provide detailed feedback to the user so that they know exactly what they have done wrong…
J Young
  • 755
  • 1
  • 10
  • 26
4
votes
2 answers

Convert factor to integer in a data frame

I have the following code anna.table<-data.frame (anna1,anna2) write.table<-(anna.table, file="anna.file.txt",sep='\t', quote=FALSE) my table in the end contains numbers such as the following chr start end score chr2 41237927 …
Anna
  • 147
  • 2
  • 4
  • 12
4
votes
3 answers

Create a unique 4-byte Integer number from a String in PHP

I have a SQL table which uses strings for a key. I need to convert that string (max. 18 Characters) to a unique (!) 4-byte integer using PHP. Can anyone help?
1 2 3
99
100