Questions tagged [int]

A data type that represents an integer. An integer is a whole number that can be negative, positive, or zero. (i.e. ...-2, -1, 0, 1, 2...) Use this tag for questions about using, storing, or manipulating integers.

int is a data type that represents an integer (a whole number - not a fraction).

int data types may vary based on:

  • the number of bits used to represent them - 16, 32, etc.
  • whether they allow both negative and positive values (signed integers) or only positive (unsigned integers).

In many (but not all) languages, integers are limited to a specific range due to the way they are stored - for instance, an ISO C 32-bit signed integer can store values from −2,147,483,648 to +2,147,483,647 (-2³¹ to 2³¹-1).

This keyword is often used in C-like languages (including C, C++, Golang, etc.)

9665 questions
3
votes
1 answer

How can I have a String attached to an array of ints?

I've done some research on this site about this already, however, I'm having some trouble finding something I can use. I'm trying to create a similar program to pokemon, but much much simpler and text based. Currently I'm using arrays to store the…
Ella
  • 103
  • 2
  • 8
3
votes
3 answers

How to convert a int to a numeric char in C#?

I wan't to convert a int to a char, but I don't want the (char)int method, because (char)3 won't give '3' but ''. So, there's a built-in way to get what I want, or I need to make it myself?
3
votes
2 answers

How Java deal with hard coded numeric values?

I have decompiled a Java class which contain this line : DatabaseError.throwSqlException((int)23); Until now i believe that Java consider that literal numeric value is int, So why they cast 23 ? And in general how Java deal with hard coded numeric…
54l3d
  • 3,913
  • 4
  • 32
  • 58
3
votes
5 answers

How does int(x[,base]) work?

The output for the following code is: int("12", 5) O/P: 7 int("0", 5) O/P: 0 int("10", 2) O/P: 2 I cannot make sense of this. From the Python documentation it says: The "[, base]" part is optional i.e it might take one or two arguments. The…
Manshi Sanghai
  • 283
  • 2
  • 3
  • 10
3
votes
3 answers

C modulus returning negative number

I have data type unsigned __int128 data; so I don't think this is a type issue, but I have no idea why it is occuring #include int main(int argc, char *argv[]) { unsigned __int128 z = 1911602146; unsigned __int128 n =…
Kendall Weihe
  • 2,021
  • 4
  • 27
  • 53
3
votes
2 answers

Run-time error. Integer convert to string

I am currently creating a program that returns the ordinal form of a number (1st, 2nd etc.). But when I run my program I get a runtime error. I am suspecting that it has something to do with my converting from int to string, but I can't seem to find…
user5316498
3
votes
2 answers

Haskell : Integer to Int with int signature

So i'm having problems with some variable types. getOrdenado :: (String,Int,String,Int,Int) -> Int getOrdenado (_,_,_,a,_) = a listaOrdenado :: [(String,Int,String,Int,Int)] -> [Int] listaOrdenado xs = map getOrdenado xs getOrdenado takes a…
eXistanCe
  • 735
  • 1
  • 9
  • 25
3
votes
3 answers

store decimal part of double as int

I am currently making an application in Swift 2 for OS X where I have a variable called x, of type double, that I do not know what it is. What I want to do with this variable x is to get the decimal value and store it as an int. This is what I want…
iProgram
  • 6,057
  • 9
  • 39
  • 80
3
votes
4 answers

C language int num to char string

How do I get from: int i = 1023 to: char string[4] = "1023" Here's my attempted code: Attempt 1 #include main(){ int avg_adc = 1023; char myString[4]; sprintf(myString, "%d", avg_adc); } //Output returned…
Arch
  • 47
  • 2
3
votes
1 answer

When is int value ordinarily converted to unsigned?

Here is from C++ Prime 5th: if we use both unsigned and int values in an arithmetic expression, the int value ordinarily is converted to unsigned. And I tried the following code: int i = -40; unsigned u = 42; unsigned i2 = i; std::cout << i2 <<…
chenzhongpu
  • 6,193
  • 8
  • 41
  • 79
3
votes
1 answer

How do I get machine-sized integer for FFI?

In dealing with foreign code, I have to take pointers to a C struct of the form typedef struct { int two; int nd; char typekind; ... } PyArrayInterface; Obviously the size of int is unknown. How do I represent this struct in…
Jackson Loper
  • 525
  • 4
  • 10
3
votes
2 answers

Print the collatz sequence of a positive int, n, one value per line stoping at 1 using python

I've done: def collatz(n): seq = n if n == 1: n = n while n > 1: if n % 2 == 0: n = n // 2 else: n = 3 * n + 1 print(seq) The corrct output for calling this function, while n = 10:…
Frank
  • 339
  • 8
  • 18
3
votes
2 answers

Finding parity of number of '1's in a int variable

Given an int variable, I would like to check if the number of '1' in its binary representation is even or odd. It can be made with xor operations like int n; int s = 0; for(;n;n>>=1) s ^= (n&1); There's some better way to do so in C++? Note:…
Exodd
  • 221
  • 1
  • 9
3
votes
4 answers

Converting large string of numbers (14 digits) to integer or long in C

I have a string that contains a 14-digit number. I want to convert the string to an int. When I use atoi(stringName), I get the max 32-bit in limitation. Example: String1 contains "201400000000" long long tempNum1; tempNum1 =…
plc
  • 33
  • 5
3
votes
1 answer

Casting values and resulting math

short x, y; short z = ((short)x) + ((short)y); So I understand that in Java that a value is considered an integer when it is added. It's just one of the nuances in the language. However, here, I am already casting short to the variables x and y…
Borla312
  • 55
  • 4
1 2 3
99
100