Questions tagged [negative-integer]
34 questions
15
votes
3 answers
How to check if a signed integer is neg or pos?
I am new to x86 assembly language, I have a signed integer saved in register eax, and I want to check if the number is negative or positive. To do that, I used bt instruction to check the first bit.
Here is what I did:
bt eax,0
jnc isNegative
bt…

Yonk
- 185
- 1
- 2
- 6
4
votes
3 answers
c++ stream negative number conversion
I came across an issue with C++ trying to read a text file filled with signed integer numbers in hexadecimal form and parsing them to vectors. I used the C++ stream to variable redirect (stream >> var), and it seems that negative numbers are not…

user3780807
- 43
- 1
- 4
2
votes
2 answers
Unsigned user-defined integer literal
Suppose I want to define an integer literal which also allows for negative values, e.g. -12_km.
I.e., I would like to do
using coord_t = long long;
coord_t operator "" _km(long long int);
However, this is not accepted by my compiler (gcc).
The…

Tim Kuipers
- 1,705
- 2
- 16
- 26
2
votes
1 answer
Is there a succinct way to split this negative integer into a list of digits? (Python)
I can do this using an if statement but I feel like the code is too long for this simple operation.
num = -12345
-->inserts magical code<--
desired output
num_list = ['-1', '2', '3', '4', '5']

Adam Zawitkowski
- 21
- 5
2
votes
1 answer
Except for python, is there any other language supporting negative index?
I just wonder is there any other programming language to support negative index.
About C, the pointer can be calculated just like number. so please except it.
But in python, my_list[-1] is the last of list.
Is Python the only language…

Michael
- 21
- 2
1
vote
2 answers
turn positive values to negative in SQL Snowfalke
I have a column where the values describe the price of an item that has been returned. They are positive and when sum:ing them I would need them to become negative.
Ex:
order id
item…

Sevgi Camuz
- 75
- 1
- 9
1
vote
1 answer
I am new to C# and I am trying to study some sorting algorithm How do I make my selection sort accept negative numbers?
Here is my Screenshot of the
output of the descending order for my selection sorting algorithm
My problem is my code doesn't accept any negative numbers and I don't know if my IDE is at fault because it accepts negative numbers in ascending but not…

iZ0N
- 21
- 1
- 4
1
vote
1 answer
Why does my CImg have negative width and height?
CImg* img = NULL;
bool loaded;
while ( !loaded )
{
loaded = true;
try
{
img = &CImg( filename );
}
catch ( CImgException )
{
loaded = false;
fprintf( stdout, "ERROR: could not load %smap…

ophilbinbriscoe
- 137
- 1
- 8
1
vote
2 answers
Iteration for negative integers
I have written a iterative function to generate result for expression:
F(n) = 3*F(n-1)+ F(n-2) + n
public int calculate(int n){
if(n == 0) {
return 4;
}
if(n ==1){
return 2;
}
else {
int…

Aquarius24
- 1,806
- 6
- 33
- 61
0
votes
3 answers
negative numbers in python
im trying to get this
rawstr = input('enter a number: ')
try:
ival = abs(rawstr)
except:
ival = 'boob'
if ival.isnumeric():
print('nice work')
else:
print('not a number')
to recognize negative numbers, but i cant figure out why it…

Luci5274
- 3
- 2
0
votes
0 answers
Oracle query for running total
I have the below table and trying to derive the result in the 'expected output' column. I have mentioned the logic on how I derive it in the 'logic' column.
enter image description here
I tried using the rows unbounded preceding
0
votes
1 answer
The hash of -1 is equal to the hash of -2 in python
Why do the negative integers -1 and -2 have the same hash?
>>> hash(-1)
-2
>>> hash(-2)
-2

amitjans
- 83
- 1
- 7
0
votes
5 answers
How to distinguish negative numbers from input that is not a number
I am trying to build a simple game and I would like Python to return a message when a player enters a negative number. My issue is that negative numbers are interpreted as strings when the player tries to enter them.
Here is my script:
while True:
…
0
votes
1 answer
How do I assign -0x80000000 to long long variable in VS2019?
I am using Visual Studio 2019 Community edition. I have the following C++ code snippet:
long long l = 0x80000000;
assert(l > 0); //true
l = -0x7fffffff;
assert(l < 0); // true
l = -0x80000000;
assert(l < 0); // FALSE
I expect -0x80000000 to end up…

Kok How Teh
- 3,298
- 6
- 47
- 85
0
votes
1 answer
Writing a javascript function for codecademy
Taking some time to try and learn Javascript to become a better developer. I am having a bit of problem with this code.
function howOld (age, year) {
let theCurrentYear = 2020;
const yearDifference = year - theCurrentYear;
const newAge =…

mbmarketing4you
- 55
- 8