695 questions
2
votes
1
answer
93
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 = (...
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;
...
0
votes
2
answers
151
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 ...
3
votes
1
answer
157
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 ...
0
votes
4
answers
187
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
1
answer
414
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 ...
0
votes
1
answer
878
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 ...
-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 ...
1
vote
3
answers
562
views
How can I perform a branchless conditional arithmetic operation in C?
I have a value int x where I want to conditionally add (for example) a value int y to, contingent on bool c. I could write code like this:
bool c; // C23, or stdbool.h macro for _Bool. Converts to ...
1
vote
1
answer
175
views
Is it necessary to convert to binary when doing addition with a hexadecimal's two's complement?
3 9 6 F E 2 + 5 3 8 A A A
This is the problem that I have to solve assuming two's complement addition. I know how to find the two's complement of each.
C 6 9 0 1 E
A C 7 5 5 6
However, most of the ...
0
votes
1
answer
455
views
int256_t using C++ boost library capable of showing 2^{256} - 1
I'm using the cpp_int header file from boost/multiprecision and for some reason when I cast -1 to a uint256_t then cast it back to an int256_t, it keeps the same value (~1.15e77). When I increment ...
1
vote
0
answers
51
views
Wrong result when adding two bignums in gass assembler
I am adding two big numbers in GAS, I have used the online big number calculator to check the sum first, which is -396,154,063,093,444,159,558. I also am using SASM, an asm IDE, and the result from ...
3
votes
1
answer
291
views
Can std::hex input format support negtive int16_t hex string with two's complement notation such as `ffff` for `-1`?
I would like to input a text string ffff to a int16_t, the value should be -1.
Here is a simple test C++ program:
#include <iostream>
#include <iomanip>
#include <stdint.h>
int main(...
-4
votes
1
answer
523
views
Does CPU work only with two´s complement? [closed]
I have some doubts about how two's complement is implemented in CPU.
Does the CPU always work with two's complement?. If not, how it knows when to apply it for substraction.
From my point of view, I ...
-1
votes
1
answer
111
views
How do you determine one's complement and two's complement in Python?
Here's what I have so far:
decimalEquivalent is variable that represents an integer.
#One's complement of the binary string is shown
onesComplement = bin(~decimalEquivalent)
print(f'The negative no (-{...
0
votes
1
answer
45
views
Int calculation from byte representation
Given bytes as HEX: 710e00fe
I do the following:
int value = (*(int*)([bytes bytes]));
int exp = value >> 24;
int mantissa = value & 0x00FFFFFF;
And I get mantissa = 3697 and exponent = -2....
0
votes
2
answers
139
views
Is twos complement a representation or an algorithm or both?
There are tons of previous threads about how to apply 2's complement and how to interpret the number which I fully understand; however, what I'm confused about is the technical definition: that is, ...
0
votes
0
answers
107
views
In fxpmath does the signed syntax represent the negative numbers as 1's complement only? If yes, how do I change it to 2's complement?
from fxpmath import Fxp
c = Fxp(complex(3.2500+2.0625j), True, 8, 4) # (val, signed, n_word, n_frac)
print(c)
print((c).bin()) # binary representation
d = Fxp(complex(2.0625+5.2500j), True, 8, 4) #...
0
votes
0
answers
67
views
what is the NOT instruction doing to eax in assembly [duplicate]
repnz scas al,BYTE PTR es:[edi
MOV eax,ecx
NOT eax
value of eax changed from 0xfffffffc to 0x3 after these lines.
1
vote
1
answer
1k
views
How is the overflow flag not set after this addition?
I'm learning about x86 assembly(8086 to be more specific) and I'm confused about the concept of flags, I tried searching about it online and found this image :
According to the image , after the ...
0
votes
1
answer
62
views
Reverse binary reading
I have a document that shows a data in HEX, and split it into multi part (head, TransactionID, MessageType and ...)
There is a problem in this document, and it is for example for TID they write ...
0
votes
1
answer
102
views
Need some assistance understanding binary addition/subtraction using 2's complement
If A = 01110011, B = 10010100, how would I add these?
I did this:
i.e: 01110011 + 10010100 = 100000111
Though, isn't it essentially 115 + (-108) = 7, whereas, I'm getting -249
Edit: I see that ...
-1
votes
1
answer
436
views
How does 0FFFFh equal -1?
mov ax, 0ffffh
inc ax
inc ax
Was watching a video on basic Intel X86 Assembly.
I thought 0FFFFH was 65535 but in the video they got -1 instead (before the inc instructions run). Just wondering how ...
0
votes
2
answers
2k
views
Converting sensor data (two's complement) to signed integer
I've seen a couple old posts that had a similar context but the answers were code snippets, not explanatory. And I can't even get the code offered in those answers to compile.
I apologize in advance ...
2
votes
2
answers
535
views
How Can I Convert Hex 'F933F177' to Decimal -114.036361 via SnowSQL or a Java function?
I have coordinates stored in HEX, which from searching online appear to have used Signed 2's Complement to handle the negative values. I'm getting a bit lost with where the various conversions are ...