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

Sum of the digits of an integer in lua

I saw a question like this relating to Java and C, but I am using LUA. The answers might have applied to me, but I wasn't understanding them. Could someone please tell me how I would get the sum of the individual digits of an Integer. For Example. a…
Mikelong1994
  • 77
  • 2
  • 7
5
votes
1 answer

NetLogo - Setting a parameter to an Integer

Setting a function parameter to an integer in NetLogo After exhausting the Documentation for NetLogo online, I couldn't find a solution to set a parameter (lets call it r), to an integer in the function declaration. In python it is as simple as…
Paolo Bernasconi
  • 2,010
  • 11
  • 35
  • 54
5
votes
5 answers

Java Possible to Return Either Float or Integer?

Is it possible to have a function that returns either Integer or Float? I want to have the 2 functions become one if it's possible: private static Integer parseStringFormatInt(String val){ System.out.println(Integer.parseInt(val.substring(0,…
prog rice bowl
  • 788
  • 3
  • 19
  • 36
5
votes
7 answers

floating and integers....?

why do we need integers and floating in processor?thank you
amy
  • 75
  • 1
5
votes
2 answers

Is there a way to simulate integer bitwise operations for _m256 types on AVX?

I have a boolean expression that I have managed to implement in SSE2. Now I would have liked to try implementing it in AVX exploiting an additional factor 2 in parallelism increase (from 128 bit SIMD type to 256). However, AVX does not support…
Toby999
  • 584
  • 1
  • 5
  • 14
5
votes
7 answers

How to check if the input is a valid integer without any other chars?

#include #include using namespace std; int main() { int x; cout << "5 + 4 = "; while(!(cin >> x)){ cout << "Error, please try again." << endl; cin.clear(); …
user2699298
  • 1,446
  • 3
  • 17
  • 33
5
votes
1 answer

How to check if a column value contains integers in oracle

Need a query that has to check whether resulting columns have integer.
user3020560
  • 59
  • 1
  • 1
  • 2
5
votes
3 answers

Safe and portable way to convert a char* to uint16_t

As mentioned in the title, I'm looking for a way to convert a char* (coming from argv) to a uint16_t. The command line argument is a port number, and so, can't be > to 65535, nor negative. Currently, I did this (compiling with -std=gnu99): #include…
Thibaut D.
  • 2,521
  • 5
  • 22
  • 33
5
votes
2 answers

Best way to store status flag value in the table (char or int)

i need to have a column called status in the table. this status column can contain -> activated , expired, deactivated. so i am wondering why cant i create an integer type column called status and store them as 0, 1, 2 (expired, activated,…
dev1234
  • 5,376
  • 15
  • 56
  • 115
5
votes
6 answers

Why is float.MaxValue 0xFF 0xFF 0x7F 0x7F and not 0x7F, 0xFF, 0xFF, 0xFF like ints?

I guess this needs little extra information. But, why is it that way? (This assumes the 23 bit float type is base on IEEE 754 32 bit binary floating point, and Little Endianness.) In 32bit ints it's pretty straightforward, since: int.MaxValue =…
5
votes
3 answers

How to return a fixed length binary representation of an integer in Ruby?

I know that I can use Fixnum#to_s to represent integers as strings in binary format. However 1.to_s(2) produces 1 and I want it to produce 00000001. How can I make all the returned strings have zeros as a fill up to the 8 character? I could use…
Alexander Popov
  • 23,073
  • 19
  • 91
  • 130
5
votes
3 answers

What are the benefits of IntegerCache while using Integer?

In Integer class, there is private static class IntegerCache. What is the use of this class? What are the benefits of it while using Integer?
Prateek
  • 12,014
  • 12
  • 60
  • 81
5
votes
2 answers

Why is division producing a negative number?

Why is this printing the negative number -147982099 instead of 8462696833 = 600851475143 / 71 import Data.List smallFactor n = case (elemIndex 0 (map (mod n) [2..])) of Just x -> x + 2 main = print( quot n (smallFactor n) ) …
user782220
  • 10,677
  • 21
  • 72
  • 135
5
votes
1 answer

java hexadecimal to int conversion - have to remove 0X ?

I have a file with many hex numbers (for eg - 0X3B4 ). Im trying to parse this file as assign these numbers to integers, but dont seem to get Integer.parseInt to work. int testint = Integer.parseInt("3B4",16); <- WORKS int testint =…
Nikhil
  • 797
  • 6
  • 12
  • 30
5
votes
7 answers

Java printing a string containing multiple integers

Just starting learning java today and can't seem to figure this out. I am following the tutorial on learnjavaonline.org which teaches you a few things and then asks you to write a code to do a specific thing, it then checks the output to see if its…
user2650243
  • 73
  • 1
  • 1
  • 4