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

Converting an int that is more than 16 digits long into a string in php

Is there any function that easily echos an integer that is 15+ digits long? The only way I've managed is like this: $num = 123456789012345; $num = number_format($num); $num = str_replace(',', '', $num); echo $num; But even this way it is only…
Ben
  • 515
  • 5
  • 18
3
votes
3 answers

How to convert Binary String to int array?

Say I have an Integer, I convert it to binary string first. int symptomsM = 867; String symptomsBit = Integer.toBinaryString(symptomsM); In this case, I would have symptomsBit as 1101100011 in binary. But how can I further…
Orangeblue
  • 229
  • 1
  • 5
  • 15
3
votes
1 answer

error while trying to get the int from a string

I want to get the int from the string, without using the int type directly to get advantages from getline() but somehow I get an error if the input is not an actual int. #include #include using namespace std; int main (int…
Amin NAIRI
  • 2,292
  • 21
  • 20
3
votes
2 answers

Error trying to convert list to an array[]

I have referenced this in an attempt to convert my list to an array, but I can't seem to get it to work. Here is what I have: int values[] = Arrays.asList(str.replaceAll("[^-?0-9]+", " ").trim().split(" ")).toArray(); The error that I am…
bob dylan
  • 647
  • 1
  • 10
  • 25
3
votes
2 answers

Converting [Int?] to [Int]

I have a String, e.g. "7,8,9,10" that I'd like to convert to an array of Int items i.e. [Int] However, my code currently gives me a [Int?] instead (an array of optional integers). Here is the code: let years = (item["years"] as! String) …
Ben
  • 4,707
  • 5
  • 34
  • 55
3
votes
3 answers

Differences between 0x01 and 0x01f

I'm looking at the original source code for Identicons. There's a bit of code that does some bit twiddling to extract red, green and blue components: int blue = (code >> 16) & 0x01f; int green = (code >> 21) & 0x01f; int red = (code >> 27) &…
Brad
  • 9,113
  • 10
  • 44
  • 68
3
votes
2 answers

Converting int to string in java is giving the answer as 1

I converted a decimal integer to binary and that binary integer when I'm trying to convert to a string is giving me 1 as the answer always when it should give the value of the string. while(a>0) { b = a%2; …
Megha
  • 121
  • 1
  • 1
  • 9
3
votes
2 answers

Possible lossy conversion from double to int and cannot find symbol

I'm getting an error in my program saying: Lyrics.java:11: error: cannot find symbol Cube(b); ^ symbol: method Cube(int) location: class Lyrics Lyrics.java:15: error: incompatible types: possible lossy conversion from double to int return…
McDodger
  • 43
  • 1
  • 1
  • 7
3
votes
2 answers

usage of str() to convert number in int() in Python

Can someone explain me why should I first convert a number to string in order to convert it after that to integer. Here is the code for example: print sum(int(number) for number in str(__import__('math').factorial(520)))
George G.
  • 155
  • 1
  • 4
  • 13
3
votes
3 answers

int and float in function overloading

I have two overloaded function like below: void print(int i) { ... } void print(float f) { ... } Its giving me this error for print(1.2);: error: call of overloaded 'print(double)' is ambiguous Can anyone explain me why?
Shahriar
  • 13,460
  • 8
  • 78
  • 95
3
votes
5 answers

How to distinguish between int and long?

public class NewMain { public static void main(String[] args) { long num = 100; System.out.println(xMethod(5,1000000000000L)); } public static int xMethod(int n, long x) { …
John Doe
  • 43
  • 1
  • 5
3
votes
1 answer

Inconsistent overflow check behavior for different types

I have this interesting piece of code: private static int ConvertToInt(dynamic value) { unchecked { return (int)value; …
RX_DID_RX
  • 4,113
  • 4
  • 17
  • 27
3
votes
2 answers

Any performance reduction to use int instead of size_t index to access vector elements?

If I use int index to access a vector element, will it convert the integer to size_t, and then call the operator[](size_t) function? Is there any performance reduction?
user1899020
  • 13,167
  • 21
  • 79
  • 154
3
votes
3 answers

How do I compare a string and an integer in Python?

I am quite a newbie in Python. I wrote this and got this error when i typed a letter in the input: TypeError: unorderable types: str() >= int() Here is the code that I wrote: user_input = input('How old are you?: ') if user_input >= 18: …
Keretto
  • 57
  • 1
  • 2
  • 9
3
votes
0 answers

Why is comparing doubles so much slower than comparing ints in Java?

On a 64-bit OS with an i5-3570k, this piece of code takes 1.19 seconds on average to execute: for (int i = 0; i < 1e9; i++); If 1e9 is replaced with 1000000000 or (int)1e9, it only takes 0.0013 seconds on average to execute. To me, it's fairly…
Dabble
  • 182
  • 1
  • 3
  • 14