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.
22,124
questions
-5
votes
0
answers
31
views
How to convert hyphenated string of variable length with hyphen at random position into integer? [duplicate]
Let's say I have a string "123-456". How do I convert it into an integer (123456)?
The length of the string and the position of the hyphen is not predefined. What's the most efficient way to ...
-2
votes
1
answer
30
views
error cannot convert int to boolean in the if else if statement in java [closed]
package Fare;
import java.util.Scanner;
public class fare {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print(" ...
0
votes
3
answers
80
views
Invert a value of bit in digit
I want to invert a value of bit in digit.
The method should invert value by number of bit, like this:
public static void main(String[] args) {
int res = flipBit(7,1);
}
public static int flipBit(...
0
votes
2
answers
35
views
How to take integer input from user in dart
i am new in dart and just want to know how to take integer input from user in dart with null safety. i found out a way to take number input from dart which is:
String? chossenNumber = stdin. ...
0
votes
0
answers
37
views
LUA hex to decimal, decimal to hex does not produce same results due to overflow
I was trying to convert a hex value to number but it seems like its not producing correct results as when I am converting the result back to hex. I am not getting same value.
outputHash = '...
0
votes
1
answer
37
views
Difference between int main(void) and int main() [duplicate]
#include <stdio.h>
int main()
{
static int i = 5;
if (--i){
printf("%d ", i);
main(10);
}
}
I was reading article on geeksforgeek the difference ...
-5
votes
0
answers
66
views
How to initialize or declare a variable in C programming? [closed]
I'm working on one of my assignments in my C programming class and I entered everything right, but I can't figure out how to initialize the integers in this code. This program is supposed to output a ...
-1
votes
0
answers
28
views
JAVA, integer n and a digit d (1-9) with loops to count the number of integers between 1 and n that end with the digit and begin with the digit [closed]
I'm a student and in this semester I have programming in java, I have this exercise to deliver but I am relatively new to the java space so I do not know how to continue the work I have done. This is ...
-1
votes
3
answers
48
views
how to loop through each element in list and increment by one
Hello i want to ask how to loop through each element and increment every time by one this is what i want first i want to sum 0 , 1, 3 ,6 , 10 and after that sum can somebody help me about that i don't ...
1
vote
2
answers
45
views
I'm trying to get the sum of these two integers on a single script so I can have it be the text as a UI score on Unity
I am trying to get the integer "pop" from the first script and the integer "clack" to be added together so that they can become a text that is the score for my game.
using System....
-1
votes
0
answers
28
views
How do I write a Java program that reads 10 digits from the keyboard and outputs those same 10 numbers in this specific format: (nnn)nnn-nnnn? [duplicate]
I am very new to Java and stumped on which method to use to convert the 10 digits into the format of (nnn)nnn-nnnn.
This is what I have tried so far, I am unsure of how to store the 10 digits from the ...
-1
votes
1
answer
36
views
Separating the lists where after conversion all values are numbers [duplicate]
To separate only the lists that converted become all numbers, I do it like this:
a = ['start','nan','1.004569','0.8554','nan']
b = ['0.464','5','4.8784','2.411474','0.44']
c = ['start','start','start',...
0
votes
0
answers
20
views
Why does int8 in sql represent 8 bytes [closed]
In sql, int8 is an alias for BIGINT, which is a signed 8 byte integer. In other languages such as golang and c, int8 represents a signed 8 bit integer, which is of course 1 byte.
What is the ...
1
vote
1
answer
15
views
Problem with filter a integer variable in SQL
I am trying to filter the data I have only for years between 2007 and 20011. The variable I want to filter is an integerano. The query is running but it is not filtering the data in this variable, but ...
1
vote
1
answer
15
views
Float to Int type conversion in Python for large integers/numbers
Need some help on the below piece of code that I am working on. Why original number in "a" is different from "c" when it goes through a type conversion. Any way we can make "a&...
0
votes
2
answers
29
views
Confused on float and integers, how to make the output exactly as it is, not round up or unnecessary ".0"
I'm trying to make a code to find the gradient of a straight line for my assignment.
It went well but unfortunately it didn't pass 3 test case because the output has decimals so it rounds up the ...
0
votes
0
answers
13
views
Why does xcode not allow me to explicitly declare type when changing string type to integer (Swift) [duplicate]
When I want to change a value from string to Integer, swift complains when I try and declare its type explicitly.
Example:
let myNum: String = "123"
let myNum1 = Int(myNum: String) // Swift ...
-1
votes
2
answers
27
views
get sum from user numbers input
I am trying to get a sum from all the user numbers input.
User enter a quantity number from dialog. The quantity is the shown on a TextView, inside the ArrayList quantity.
In the ArrayList quantity, i ...
1
vote
2
answers
73
views
how to make cin only take integer inputs
i new to programming and we are required to create a program that dont exit when the user inputs the wrong input, but i only learned the basics so far.. i already solved when the number is above and ...
-1
votes
1
answer
29
views
My int is not taking the value of another int. This is in C, using visual studio
I cannot understand why image[i][j].rgbtBlue in the below code will not take the value of debug_blue_third. I'm probably making a stupid error, but I've been trying to figure it out for hours so any ...
-2
votes
2
answers
27
views
Save int value when restarting game [closed]
I'm currently making a snake game in java and I have a death menu where every time I die, the menu launches. I have a highscore aswell, the thing is that the highscore is not saving and restarting ...
-3
votes
0
answers
26
views
How to add negative integers numbers to program, which convert int to binary [closed]
I have a little problem. Because I want, to my program convert int numbers to binary.
And I found code, but its only works for positive numbers ( numbers > 0).
But I want to works with negative ...
0
votes
1
answer
31
views
Why an Int32 variable can't be assigned to an Int64 variable or vice versa in Swift?
I could not assign Int32 var/let to Int64 var/let or vice-versa in Swift. I get a compile time error when I attempt to do so. What is the reason behind this ?
-1
votes
1
answer
27
views
How toMake Math.random generate number between 1 and 1000? [duplicate]
So I'm trying to figure out how to print out a random number between 1 to 1000.
I tried:
double a = 1+ (Math.random()*1000);
System.out.println(a);
But when I try this i get numbers with ...
0
votes
3
answers
59
views
Fast way to find bit length of large positive integer from decimal
Given the decimal string representation of a large positive integer, what's a fast way to find the integer's bit length? Using int() and then bit_length() is slow. This example with a million digits ...
0
votes
2
answers
48
views
How to receive long array of integers with TCP socket in C?
How can I send and receive a long array of integers using TCP sockets?
In the case of short array, the reception is possible using the function recv(.., 4*size of array) one time, however when the ...
0
votes
0
answers
21
views
In Python - how to retrieve the binary code of negative integer from the memory? [duplicate]
I want to get a binary code of integer in Python.
I know about the bin() function.
But firstly bin() is not retrieving, but converting.
And secondly, it doesn't work with negative integers - I mean ...
0
votes
1
answer
63
views
What can I store in a char?
I know that letters/one-digit-numbers can be stored in chars,
char letter = 'c';
char number = '1';
but can emojis or forgain letters be stored in a char? If not, how can I store them?
Is this ...
2
votes
2
answers
28
views
How to make the code accept both int and float type values as double type? - Python
I have dataset which have mixed values, in which few values are float(e.g. 3.4) and few are int (e.g. 3.0). I want to check if all the values are double. I want that if the values are either int or ...
0
votes
1
answer
43
views
Looking for a fast way, to represent the value of an integer, by a number in the range 0 to 3 (without branching?)
Given that val is some random integer,
and number the possible outcome:
if the value is less then &H100 ; the number is 0
if the value is less then &H10000 ; the number is 1
if the value is ...
0
votes
1
answer
12
views
Python: Add Two Integer Lists of Different Lengths Together as One List
What I have:
first = [1,2,3]
second = [1,2,3,4]
What I want:
third = [2,4,6,4]
first + second = third
I've tryed using numpy and zips but they all stop after the smallest list is complete.
0
votes
0
answers
20
views
Converting Category Data Type to Integer Data Type
I have a dataframe with a column (birthyear) that supposed to be integer but it's in category data type. I have used df.birthyear = df.birthyear.astype('int') to convert to Integer, I keep getting
...
0
votes
2
answers
71
views
c++ reinterpret_cast char to int* / adjacent bits are repeatedly set as 1100
Why does the second example find 1100 instead of 0000 after storing the address in the int pointer and then reading the adjacent bits?
Example 1:
char c = 'a';
int val = *reinterpret_cast<int*>(...
0
votes
1
answer
36
views
Sending int through shared memory between two processes
I would like to send an int from one process to another through shared memory.
I tried simply placing the value of the int into the shared memory (&number) - didnt work.
I tired casting the string ...
1
vote
2
answers
57
views
Printing string inside of an integer array
I am trying to print a string in between integers. How should it be done
-1
votes
1
answer
35
views
when I input string instead of integer then why it does print 0 and 1 on VScode?
when I input string instead of integer then why it does print 0 and 1 on VScode?
#include <iostream>
using namespace std;
int main()
{
int a , b ;
cout<<"give the value of a ...
-2
votes
0
answers
25
views
Syntax Error invalid syntax values issue with python [duplicate]
I have actually made a program that will scan the whole Devices on the same network but the stupid issue that I got from python it turns out it was coming from python 3.10 not python 2.7 I can fix it ...
1
vote
3
answers
36
views
How to add a comma after every three digits? [duplicate]
Add a character in between a string
How can I add a comma after every three characters in a string? For example, i have a string number = "2000", and the program should add a comma to the ...
0
votes
1
answer
36
views
LeetCode 7: Reverse Integer | why does it work with a long but not with an int?
I was trying to solve this problem on LeetCode where you have to reverse an integer using a function. The constraint is that if the reversed number goes outside the signed 32-bit integer range, i.e. (-...
0
votes
1
answer
26
views
Simple way to convert time text strings to ints for numeric operation in Qliksense data load editor
TimeTemp displays as such 168@06:43:23AM
stationTime displays opening and closing times of service area stations as such 6AM-10AM
I’ve separated TimeTemp into 2 different columns, initialTemp and ...
0
votes
4
answers
57
views
PHP, how to convert Int value to Week days
For saving the days of week in a database, I've the existing code :
if (isset($_POST['day7'])){$dayOfWeek = 1;} else { $dayOfWeek = ''; }
if (isset($_POST['day1'])){$dayOfWeek = $dayOfWeek + 2;}
if (...
-3
votes
2
answers
52
views
how i can convert char array to int without use parseInt and String.valueOf() (java) [closed]
need to convert char array to int without use parseInt and String.valueOf(),
need to realize this method
public static int parseInt(char[] str) {
}
for example, if the input data is char[] str = {...
1
vote
1
answer
37
views
'Int object not callable'
I am attempting to calculate the variance of my list without using the sum function or other libraries. No matter what I change, I receive 'int object is not callable'. This is what I have so far.
...
-1
votes
2
answers
40
views
Display items in ArrayList only over a specific number in Java
I am working on a program that has to display only the items in an ArrayList whose value is greater than 10. I am using the toString() method to display the items, but I want to display only the items ...
0
votes
0
answers
11
views
How to remove a number from an array if the number is less than 800? [duplicate]
I have an array that contains integers:
var _ListsvotesArray = [600, 2000, 6000, 400,1000];
// declare number of voters and number of seats
var _NumOftotalVoters = 10000;
var _NumAssForRegion = 13;
/...
0
votes
0
answers
22
views
How store integers given in a line in diferent variables? [duplicate]
If i have given serie of numbers separated by spaces, for example:
INPUT
1 5 8 4
How can i save these integers in 4 diferent variables for each one?
like:
x= 1;
y=5;
z= 8;
a= 4;
1
vote
1
answer
19
views
C#: 2 4 Digit numbers into 2 bytes each and convert that to a Uint32
I got 2 4 digit numbers.
I need to get them in 2 Bytes each and convert them afterwards to Uint32.
Am i doing it correct?
byte[] data = new byte[4];
byte b1 = (byte)OldPin, b2 = (byte)(OldPin >> ...
0
votes
1
answer
21
views
Comparison of two values from a column in pandas dataframe causing a TypeError
I'm trying to build a new column in my pandas dataframe, raw_data, called CyclesTest. I want it to contain a value, cycle_test, that begins at 1. Every row of this column will contain the number 1, ...
0
votes
0
answers
29
views
How can I get an Integer out of a textfield in Xcode 13
Hi I am kinda new to Swift and coding at all.
I need the input that the user gave in the textfield as an Integer.
Can someone help me with that problem?
struct FirstView: View {
@State var score ...
0
votes
1
answer
25
views
TypeError: 'int' object is not callable; perhaps you missed a comma?
I did my research but I can not figure out why I am getting this error. Here is my code:
import numpy as np
def F(t):
c = 3 * (10**-7)
P = 1
F_0 = np.sqrt (4 * np.pi *...