695 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
2
votes
1
answer
94
views
Different result by cast negative double to uint with .NET Framework 4.7.2 and .NET 9.0 [duplicate]
I'm migrating my project from .NET Framework 4.7.2 to .NET 9.0.
Now I see that casting a negative double to uint is different.
.NET Framework 4.7.2:
double codeDouble = -2147287039.0;
uint codeUint = (...
0
votes
0
answers
29
views
Detecting overflow in two’s complement multiplication by 2 – which bits need to be checked
Given a number with a width of n bits representing a signed number in two's complement, what is the minimal number of bits that need to be checked and which ones, in order to know whether there will ...
4
votes
3
answers
187
views
Overflow arithmetic in C programming language
My platform is x86_64, and assume there are 3 variables whose types are all uint16_t:
uint16_t a, b, c;
And for the following two code snippets:
(1)
uint16_t tmp = b - a;
uint16_t result1 = c - tmp;
...
2
votes
3
answers
298
views
Is Two's Complement and Signed Integers the same thing?
When somebody says a number is represented as two's complement is it safe to write code that will represent the value in a signed integer? Does it depend on the CPU?
how does c compiler handle ...
0
votes
2
answers
157
views
2's complement operator on C
I'm reading The C Programming Language by K & R 2nd edition and got to the bitwise operators. Why, on C, the Complement (~) Operator applied to a N number, returns -(N + 1) ? When it normally just ...
-1
votes
1
answer
54
views
Is there a way to make Python interpret `~3` as an unsigned integer?
Is there a way to make Python interpret ~3 as an unsigned integer?
3
votes
1
answer
162
views
How is std::atomic implemented on platforms that do not use two's complement? (C++11/14/17)
std::atomic::fetch_add() (or atomic_fetch_add() in C11) is based on two's complement for operations on signed integers. This is a different convention from the usual signed integer arithmetic, in ...
1
vote
1
answer
160
views
Subtraction producing a negative number in assembly - what is the hex value?
I'm very new to assembly so I don't know if this is a stupid question, but I have a question where I'm being asked to read the following line of assembly and say what value is stored in %rdi ...
0
votes
4
answers
197
views
Portable implementation of computing high 64 bits in widening 128 bit multiplication
How could I implement signed and unsigned multiplication of two 64 bit numbers, widened into 128 bits, and discarding the low 64 bits, returning the high 64 bits? The multiplication must properly wrap ...
0
votes
0
answers
48
views
Adding two negative Hex numbers
I am trying to add two hex numbers given in two's compliment: A415 + A555. I'm having a bit of trouble with understanding the two's compliment inversion for adding.
I converted both numbers to binary ...
0
votes
1
answer
430
views
Is the rule for unsigned integer overflow, the carry in matches the carry out?
I'm reading a textbook on systems programming and it states that an overflow occurs for unsigned integers if and only if the carry-in bit is mismatched with the carry-out, in the left-most bit.
So if ...
4
votes
2
answers
112
views
How does Variable > -1 exactly evaluate in C?
#include <stdio.h>
#include <stdint.h>
int main()
{
uint16_t peter = 8;
uint32_t peter2 = 8;
if(peter > -1)
{
printf("Peter true\n"); //expected
}
...
0
votes
1
answer
893
views
How are negative numbers stored in "hard" memory when they are encountered during compilation?
I am in the process of learning C/C++, so for some this might be a basic question but it is confusing to me.
Beautiful answers are given here related to how we interpret positive and negative numbers ...
0
votes
1
answer
115
views
Switching a value from positive to negative using binary and twos complement
So for my college computing course(UK), we were assigned a homework task to change a user's input to its negative equivalent (1 to -1, 13 to -13 etc...) but I cant figure out how to do it. I've got ...
-1
votes
2
answers
124
views
Relational operators precision
i have a question about relational operators
are they always give correct results ?
because if we run this line of code it will result 1 instead of 0
cout<<(ULLONG_MAX==-1);
and if we keep ...