# Questions tagged [integer]

5068 questions

9

votes

3

answer

212

Views

### max/min function on list with strings and integers

I've got a list with strings and integers and want to find the minimum value of the integers, without list-slicing. Is there a work-around?
arr = [5,3,6,"-",3,"-",4,"-"]
for i in range(len(set(arr))):
cut = min(arr)
Many Thanks!

1

votes

2

answer

4k

Views

### size of long int and int in C showing 4 bytes [duplicate]

This question already has an answer here:
What does the C++ standard state the size of int, long type to be?
24 answers
I did the following experiment to know the size of long int and int in my system
System spec:
64 bit windows 7
gcc MinGW compiler
eclipse CDT
I got confused with the output I got....

0

votes

0

answer

26

Views

### R: How to convert long number to string to save precision

I have a problem to convert a long number to a string in R. How to easily convert a number to string to preserve precision? A have a simple example below.
a = -8664354335142704128
toString(a)
[1] "-8664354335142704128"
b = -8664354335142703762
toString(b)
[1] "-8664354335142704128"
a == b
[1] TRUE...

1

votes

2

answer

6.4k

Views

### How to compare two unsigned integers (uint8_t) in c

I have two uint8_t pointers in my program and I want to compare the values of those. I don't have good idea to deal with unsigned ints. Here is my code
static void bacast_signed_message()
{
uint8_t *M = malloc(MAX_M_LEN*sizeof(uint8_t));//uint8_t M[MAX_M_LEN];//uint8_t *M;
int M_len = MAX_M_LEN;;
ui...

-3

votes

0

answer

17

Views

### guess a number between 1 and 100

I am thinking of a number from 1 to 100. You and your sibling have gotten into a fight over who gets the last brownie. Write a program that comes up with a secret number between 1 and 100 and prompts each user for an integer. Whatever number is closest to the secret number wins. Be sure that your pr...

7

votes

2

answer

136

Views

### Integral promotion and operator+=

I need to eliminate gcc -Wconversion warnings. For example
typedef unsigned short uint16_t;
uint16_t a = 1;
uint16_t b = 2;
b += a;
gives
warning: conversion to 'uint16_t {aka short unsigned int}' from 'int' may alter its value [-Wconversion]
b += a;
~~^~~~
I can eliminate this by
uint16_t a = 1...

1

votes

0

answer

9

Views

### INPUT[type=number] loses digits above Number.MAX_SAFE_INTEGER

In my app, I have a value that is a 64-bit integer, output as the following HTML element:
In Firefox, when the element is loaded, it shows the value "9123372036854776000", and the adjustment arrows stop functioning.
This appears to be by design, as per the relevant section of the HTML spec:
The algo...

1

votes

2

answer

111

Views

### How are integer literals stored?

Does a small integer literal in C# (e.g.12) uses 4 bytes of stack like an integer variable? Does it need 4 bytes?

3

votes

6

answer

132

Views

### Why/how does gcc compile the undefined behaviour in this signed-overflow test so it works on x86 but not ARM64?

I was self-studying CSAPP and got a strange result when I ran into a strange issue during the run of a assertion test.
I'm not sure what to start this question with, so let me get the code first (file name visible in comments):
// File: 2.30.c
// Author: iBug
int tadd_ok(int x, int y) {
if ((x ^ y)...

0

votes

0

answer

4

Views

### Several Questions to get a code on CPLEX IBM ILOG

My dear readers.
I am a super beginner of computer coding.
Now I am trying to build a code by using CPLEX IBM ILOG.
There are some Questions. ;)
Every time I run my solver, I got a message with sudden stop, "OplRun is not responding, you must relaunch the RunConfig"
So, I find IBM homepage and I did...

1

votes

1

answer

74

Views

### Optimization: Oj algorithms (java) versus SCIP (python)

Does anybody know how these 2 solvers, (Oj algorithms) from Java and SCIP for Python, relate to each other performance wise (as in: which one is the fastest), when dealing with a typical MILP (Mixed Integer Linear Programming) problem? On first sight, I can't seem to find anything online that can po...

1

votes

1

answer

141

Views

### How to get an unsigned integer from a byte array in Kotlin JVM?

Kotlin 1.3 introduced unsigned integer types, but I can't seem to figure out how to get an unsigned integer from a ByteArray in Kotlin JVM.
Kotlin Native has a convenient ByteArray.getUIntAt() method, but this does not exist for Kotlin JVM.
val bytes: ByteArray = byteArrayOf(1, 1, 1, 1)
val uint: UI...

1

votes

6

answer

68

Views

### Extract only digits for each string from list of strings?

Currently, I'm doing a bit of web scraping. One of my extractions returns full IDs for each item on the site.
Looks like:
['ID: 1234', 'ID: 456', 'ID: 8899']
I would like to run an iterator that returns only integer values from each item in the list.
Like (preferred):
[1234, 456, 8899]
I've seen...

1

votes

1

answer

66

Views

### How to handle answer of long long integers in swift [duplicate]

This question already has an answer here:
Modulus power of big numbers
4 answers
I have to calculate power of two long integers in swift.
Swift gives an error of NaN (not a number) and fails to answer.
e.g
pow(2907,1177)
The main process id to calculate power and get remainder (a^b % n) where a=...

1

votes

1

answer

1.1k

Views

### How to convert an integer to binary form in Go and vice versa

How do i convert an Integer to binary form?
I'm currently working on a program that takes an integer and converts it to binary form.
It should also take the binary number and reverse it and convert it back to an integer and print it out.
i.e.
12 -> 1100 -> 0011 -> 3
So the program should basically:...

1

votes

3

answer

610

Views

### How to use C# Generics to limit method to integer types and still use operators

Can I use generics to create a method that takes integer types, and is still be able to do basic mathematical operations inside the method on those types?
My situation: I wrote a method that takes a value of type int and returns whether the value is prime or not. I later needed that method to work o...

1

votes

2

answer

493

Views

### Why narrow casting in java allowed from long to byte

We can cast a larger number type, such as a long, into a smaller number type,
such as a byte. for exp:
long l = 130L;
byte b = (byte)l;
When compile, we don't get a runtime error, even when the value being narrowed is too large
for the type (in this case byte).
Ideally compiler should complain, but...

21

votes

5

answer

1.8k

Views

### Is a negative integer summed with a greater unsigned integer promoted to unsigned int?

After getting advised to read "C++ Primer 5 ed by Stanley B. Lipman" I don't understand this:
Page 66. "Expressions Involving Unsigned Types"
unsigned u = 10;
int i = -42;
std::cout

79

votes

13

answer

114.2k

Views

### Int division: Why is the result of 1/3 == 0?

I was writing this code:
public static void main(String[] args) {
double g = 1 / 3;
System.out.printf("%.2f", g);
}
The result is 0. Why is this, and how do I solve this problem?

0

votes

0

answer

6

Views

### How could I get a code for 'Ensure the Equipment continuing uptime and downtime process'

My dear readers.
Now I am using Cplex(IBM Opl ILOG studio)
I am trying to make a code for Equipment operation.
as a constraints (subject to).
Here is a situation.
Equipment 'A' has a limit uptime to operate, 2hours.
and also has a downtime for maintain at least 1hours.
Each time 't' and total t is 1...

1

votes

3

answer

1.4k

Views

### Convert vector<string> * char to int

I need help in my following code and hope that you can help me through. All I wanted is to pass in INT type to setX() and setY(). However, there is no way for me to convert vector char* to int. Is there alternative to this?
template
vector Delimiter(T inputString){
int count=0;
char str[inputString....

1

votes

1

answer

1.3k

Views

### Check if argument is not Integer

This checks if argument is an integer in Bourne Shell Script:
if [[ $3 =~ ^[0-9]+$ ]] && (( $3 >= 1 ))
How do I check if argument is not an integer (can consist of integers and alphabets)?
So, I guess it's just the complement of above, but I'm not sure how to change it.
Where can I find info on wha...

1

votes

1

answer

627

Views

### extending operator overload in C++

I am fairly new in C++ (I have spent all my life in C so I thought it's time to invest some time in learning a new language in order to enrich my knowledge :) ). I have a class named "Rational", I have all its specific functions for getters, setters, constructors, etc.(it's not relevant here). The i...

1

votes

4

answer

3k

Views

### Java Converting String into Integer for Comparison

I am writing a compareTo method for the Comparable Interface for a specific class. I need to take two different strings and compare them and see if one holds a greater value than the other. I would normally use .compareTo() but in this case it is giving me an error and not working.
This is what I h...

1

votes

1

answer

1.1k

Views

### Convert long string to integer without parseLong or parseInt

Here's is the situation ... i have a binary file which contains 32-bit binary strings of characters (e.g 1011011100100110101010101011010 ) and i want to convert this to integer ... I have already tried to do it with parse-Int but if the most significant value is 1, i get back a negative number and...

1

votes

2

answer

138

Views

### In Python 2.* division which has more overhead?

Let's say I want to divide two variables, in Python 2.* (mainly 6 and 7), that are considered integers. For instance:
a, b = 3, 2
print a/b
# Prints "1"
Now, there are at least two (non-redundant) ways I know of to cause this division to be normal, floating point division (without running a from __f...

1

votes

1

answer

279

Views

### Why does android.content.ContentResolver.delete return an integer?

Just wondering, is there any other reason than "because the developer decided to do so" for android.content.ContentResolver.delete to return an integer?
Shouldn't it return a long, in case one deletes more entries than an integer can store?

1

votes

1

answer

3.5k

Views

### Converting int/long zero to double

Considering this code snippet:
int i = 0;
double d1 = (double) i;
long l = 0L;
double d2 = (double) l;
Running this on my machine prints 0.0 for both conversions. But can d1 and d2 ever be anything but 0.0?
As I understand, this is a widening primitive conversion to which the spec says:
A widening p...

27

votes

4

answer

1.3k

Views

### Assigning value to bit-field doesn't give same value back

I saw below code in this Quora post:
#include
struct mystruct { int enabled:1; };
int main()
{
struct mystruct s;
s.enabled = 1;
if(s.enabled == 1)
printf("Is enabled\n"); // we think this to print
else
printf("Is disabled\n");
}
The output of the code is unexpectedly,
Is disabled (!!)
Though the...

1

votes

1

answer

367

Views

### Sorting integers based on their prime factors

I am kind of stuck how to sort integers based on their greatest prime factor in ascending order. For example, we have 3 and 8. The order should be: 8, 3 because 8's prime factor (2) is less than 3's prime factor (3). If we have the same greatest prime factor for 2 numbers like 9 and 27, then the sma...

1

votes

3

answer

212

Views

### C# dividing an integer array using pointer

So I have a quicksort algorithm, i have to divide my integer array in to two, and call both arrays back recursively.
partition(array,lower);
partition(&array[lower + 1], array.Length - lower - 1);
But c# won't accept that code, even though i tried adding unsafe, to partition class, so i wonder what...

1

votes

2

answer

210

Views

### Comparing Integers in Java [duplicate]

This question already has an answer here:
Java: Integer equals vs. ==
5 answers
Integer wrapper objects share the same instances only within the value 127? [duplicate]
5 answers
JAVA: Comparison not working when Integer larger than 128
3 answers
If we have expressions something like the following...

1

votes

2

answer

70

Views

### How the string is add to integer in PHP

Today i very much wondered, that if the string contain first letter has integer you can add that value into another integer variable.
$a = 20;
$b = "5doller";
$a+=$b;
echo $a;
Will any one can explain how this is happen and if i have like string like "dollar5" it wont add.

1

votes

1

answer

337

Views

### How do I test if an iterator value has integral type?

While writing a C++ template function, I have to check that the variable type used by this function is integral. If it is the case, it should result in a compilation error.
template void foo( IT first, IT last ) {
// check here that *first has integral type.
}
The trouble I have, is that this funct...

1

votes

1

answer

484

Views

### Trying to create a HashMap after reading data from file. Getting null values. What am I doing wrong?

I am trying to read from a file to create a HashMap.
The inputFile is in the following format:
A B C D
1 -1 2 -3
2 3 -5 3
-3 2 7 -5
4 3 1 1
This input file represents distances between all pairs of points. Which means, it represents the following matrix:
A...

1

votes

1

answer

98

Views

### Integer overflow in operations

Following code:
UINT32 dword = 4294967295;
if(dword + 1 != 0) // condition
In such operations is there any warranty that the biggest (whole) register (avaiable on architecture) is always used? and above condition will be always true on 64 bit mode, while false for 32 bit mode?

1

votes

4

answer

4.4k

Views

### The method write(int) in the type BufferedWriter is not applicable for the arguments (Long)

I am getting the above error when I try this
for (int i = 0 ; i < uaCount.get(args[1]).occurrences ; i++)
{
out.write(uaCount.get(args[1]).singleValues.get(i));
}
Occurrences and singleValues are defined here:
public static class NumberHolder
{
public int occurrences = 0;
public int sumtime_in_milli...

1

votes

4

answer

445

Views

### What's the reason for this seemingly overengineered code for checking one number is a multiple of another?

According to this answer if I want to check one number is a multiple of another I can use the remainder operator %.
if( number % anotherNumber == 0 ) {
number is a multiple of anotherNumber
}
Yet in this fun project which is full of intentionally overengineered code they use the following approach:...

1

votes

1

answer

209

Views

### Detect an integer overflow in ASCII-to-integer conversion

I have a buf char* with ASCII digits where I need to convert to an integer value on 32-bit machine.The INT_MAX constant from limits.h header give me: printf("%d\n",INT_MAX) = 2147483647. I added plus one,and put exactly this number to my function convert. By it doesn't catch up such large integer va...

1

votes

2

answer

820

Views

### 0-1 optimization with absolute value (equiv., with two inequalities)

The bintprog command from the Optimization Toolbox solves 0-1 programming problems with an inequality constraint and an optional equality constraint: Ax