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
1 answer

Why can an Object be cast as an Integer using generics in Java?

I found a way to add Floats to an Integer array through generic types. I'm curious why Java doesn't catch this in a runtime error? I tried looking through the docs for any info about this, but I haven't had any luck. For example, say I have two…
exhausted
  • 57
  • 6
5
votes
5 answers

Check if two numbers have same digits

I need to write a program which will check if two numbers have same digits. For example: a = 4423, b = 2433; Even though their digits don't appear the same amount if times, they have same digits. #include #include int…
user17936437
5
votes
1 answer

as.integer() on an int64 dataframe produces unexpected result

I was reviewing some code and came across this odd result. If you have a dataframe with one value of type integer and you coerce it to integer you get what I think you would expect: library(dplyr) tibble(x = as.integer(c(1))) %>% as.integer() [1]…
Ben G
  • 4,148
  • 2
  • 22
  • 42
5
votes
1 answer

assign integer order to decimal numbers

I have 200 numbers all between 0 and 1. I would like to rank them and assign integer values 1-199. It could be something very easy to accomplish but i don't know which function to use - the order function does not really work. say here is what I…
vanilli
  • 131
  • 2
  • 4
5
votes
3 answers

Java double division positiveness

Why does this java code yield Positive Infinity? double d = 10.0 / -0; System.out.println(d); if (d == Double.POSITIVE_INFINITY) System.out.println("Positive Infinity"); else System.out.println("Negative…
Galen BlueTalon
  • 173
  • 4
  • 20
5
votes
1 answer

How do I convert a Float to an Int in Elm?

If I have a Float value and I want a Int to use elsewhere how do I make that conversion?
Brock
  • 925
  • 5
  • 9
5
votes
3 answers

How to find out all integers between two real numbers using R

Problem: how can I write a function that receives a and b as inputs and returns all integers inbetween them. So, assuming we have a function called integers_inbetween that behaves like this, we should expect the following examples: # Returns an…
Jake Parker
  • 241
  • 1
  • 7
5
votes
1 answer

How can I bit-convert between Int and Word quickly?

The Haskell base documentation says that "A Word is an unsigned integral type, with the same size as Int." How can I take an Int and cast its bit representation to a Word, so I get a Word value with the same bit representation as the original Int…
Isaac van Bakel
  • 1,772
  • 10
  • 22
5
votes
2 answers

How do I convert an array of integers to binary?

for (int i = 0; i < n; i++) { arr[i] = scanner.nextInt(); } String[] bin = new String[n]; for (int i = 0; i < n; i++) { bin[i] = Integer.toBinaryString(arr[i]); } The above code will convert the the whole array of integers into an array of…
Rashid Raza
  • 53
  • 1
  • 8
5
votes
3 answers

How do I get jq to preserve bigint values?

I have a large JSON file that contains bigints with their full values--not rounded like JavaScript loves to do by default. We have a workaround to deal with the bigints in Node.js, but I'm trying to use jq (the command-line tool) to clean up our…
Brandon
  • 695
  • 10
  • 29
5
votes
3 answers

C# split integer in parts given part weights algorithm

I have an integer and a list of non-negative weights, how can I 'split' the integer into same number of 'buckets' with corresponding weights? public int[] SplitIntoBuckets(int count, int[] weights) { // some magic algorithm …
wondra
  • 3,271
  • 3
  • 29
  • 48
5
votes
2 answers

Storing an array of integers with Django

I've been trying to store an array of integers in a field of a Django model. Based on this reply, I've been trying to do so using a CommaSeparatedIntegerField, however this has proved less intuitive than the name would imply. If I have a…
storm
  • 65
  • 1
  • 4
5
votes
1 answer

DRF - Array of integers

I need to post an array of integers to a DRF serializer. The serializer is: class ItemSerializer(serializers.Serializer): id = serializers.IntegerField(required = False) selected_items = serializers.ListField(child =…
5
votes
3 answers

Passing a string with hyphens gets evaluated as an integer (subtractions!) js

I am trying to pass a value like "108-17-014" to a function through onClick... hyphenatedId = "107-17-14" dialogBody += " link title"; And inside…
sova
  • 5,468
  • 10
  • 40
  • 48
5
votes
3 answers

Shopify - Convert Int to String in Liquid

How do you change the datatype from a number to a string in liquid? This could be used to create dynamic css classes within blocks. However, if it comes through as an integer it isn't recognized as a class. {{block.id}} // Integer I have answered…
shanestreator
  • 69
  • 1
  • 1
  • 7