Questions tagged [integer-overflow]

Integer overflow occurs when the result of an operation is larger than the maximal value that can be represented by the underlying integer type.

1056 questions
0
votes
3 answers

What happens when you perform ++ operation on an integer with it's max possible value?

So, it's a classic but I can't find a decisive answer anywhere. Suppose I've an integer 'x'. I'm performing the "++" operation in a loop. Something like this: int x=0; while(true){ x++; print(x); } I suppose the output will rotate form…
BlueFlame
  • 31
  • 1
  • 1
  • 5
0
votes
1 answer

Gini coefficient, ineq package in R and integer overflow

I want to calculate the Gini coefficient for each column in a 2090 x 25 dataframe. I am using the Gini function in the ineq package and the following code: gini <- sapply(mydata, function(x) ineq(x,type="Gini")). This produces results that look…
0
votes
1 answer

AS3: Adding 2 positive integers yield negative integer

I was making a Pascal's triangle in AS3. And in the results I find that, the addition of 1037158320 and 1166803110 yields -2091005866, a negative integer! This is weird. I first thought that the magnitudes were too great for an int to hold, but the…
hello all
  • 252
  • 2
  • 17
0
votes
2 answers

How to fix a int overflow?

I'm having a python code that uses the number 2637268776 (bigger than sys.maxint in 32-bit systems). Therefore it is saved as a long type. I'm using a C++ framework bindings in my code, so I have a case where it's being converted into int32,…
iTayb
  • 12,373
  • 24
  • 81
  • 135
0
votes
2 answers

How to correctly get a size in bytes from a size in bits?

Suppose you are using a bit set or something similar, essentially some object that allows you to access the value of individual bits. It may be something simple like an integer word or an array of bytes, or something more generic like a BitSet in…
user2027342
0
votes
2 answers

A hash function like from K&R book

Consider this function: unsigned hash(char *s) { char *p; unsigned hashval; for(p = s; *p; p++) hashval = *p + 31 * hashval; return hashval; } How can I measure how many bytes in s will returns a wrong result,such as overflow? I'm on…
Jack
  • 16,276
  • 55
  • 159
  • 284
0
votes
1 answer

What causes a SQLite "integer overflow" exception?

I got the following stack trace via ACRA. Galaxy Note II, Android 4.1.2: android.database.sqlite.SQLiteException: integer overflow (code 1) at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method) at…
Tom anMoney
  • 1,231
  • 1
  • 14
  • 29
0
votes
5 answers

Hashing overflow

int hash (const string &key, int tableSize) { int hashVal = 0; for (int i = 0; i < key.length(); i++) hashVal = 37*hashVal + key[i]; hashVal %= tableSize; if (hashVal < 0) /* in case overflows occurs */ hashVal +=…
user1559792
  • 347
  • 2
  • 6
  • 15
0
votes
1 answer

checking for integer overflow in c# without throwing an exception

What is the best way to check for integer overflow if I am adding 2 positive numbers together in c# if overflow isn't a condition that should cause an exception? Can i just check if the result is negative then it is an overflow?
Koda
  • 1,709
  • 3
  • 14
  • 15
0
votes
3 answers

Using integer format specifier instead of short int: Why does the code behave like this?

When I provide the following program with 4 integers as input (say a = 10, b = 20, d = 30, e = 40), it calculates c = a + b = 0 and f = d + e = 70. I know this unusual behavior is because I am using the wrong format specifier for short int, but what…
Bonz0
  • 373
  • 2
  • 5
  • 17
-1
votes
1 answer

Printing answer directly using cout gives wrong answer, whereas storing the answer and then printing using cout get accepted

I am solving problem 1A : Theatre Square(https://codeforces.com/problemset/problem/1/A) on Codeforces. Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a…
tarungaur
  • 21
  • 4
-1
votes
1 answer

how to calculate the remaindor of a to the power of b divided by ten to the power of nine plus seven

I have written a code to calculate a to the power of b and then calculate pow(a,b) % 1000000007 1000000007 = pow(10,9) + 7 a and b are integers in range 1 <= a,b <= 10000000 obviously, pow(a,b) is a very huge number so I think overflowing is…
Fateme
  • 41
  • 4
-1
votes
1 answer

Sum of postive intergers in a list is negative

I am trying to calculate intensities in different regions in a image(taken in 16-bit). I have created binary masks first of the different regions, then using the masking I calculate the intensities. However, the problem was I was getting a negative…
Deep
  • 79
  • 1
  • 1
  • 7
-1
votes
2 answers

How can I get an integer number with 99 digits by scanf in c language?

I need to get an integer number with 99 digits. This is actually the question which I need to get an integer number with 99 digits to solve: https://quera.org/problemset/9774/ This is my code to solve that question but it should be able to get…
-1
votes
1 answer

How to detect an overflow on assembler risc-v?

I am trying to implement a recursive factorial function in RISC-V assembly language that raises an error if there is an overflow. However, I am struggling to detect it. Is there a solution for this ? `