Linked Questions

165 votes
2 answers
12k views

For a school project, I've to code the C function printf. Things are going pretty well, but there is one question I can't find a good answer to, so here I am. printf("PRINTF(d) \t: %d\n", -2147483648)...
Arthur Thévenot's user avatar
5 votes
2 answers
1k views

Why is 1 not greater than -0x80000000. I know it has something to do with overflow. But can someone explain why? is 0x80000000 not a constant I think it is? assert(1 > -0x80000000); The assert ...
Negative Zero's user avatar
252 votes
3 answers
31k views

-2147483648 is the smallest integer for integer type with 32 bits, but it seems that it will overflow in the if(...) sentence: if (-2147483648 > 0) std::cout << "true"; else ...
benyl's user avatar
  • 2,097
28 votes
4 answers
5k views

Consider the following program. #include <stdio.h> int negative(int A) { return (A & 0x80000000) != 0; } int divide(int A, int B) { printf("A = %d\n", A); printf("negative(A) = ...
merlin2011's user avatar
  • 76.4k
16 votes
2 answers
6k views

I was working on an embedded project when I ran into something which I thought was strange behaviour. I managed to reproduce it on codepad (see below) to confirm, but don't have any other C compilers ...
avanzal's user avatar
  • 173
16 votes
2 answers
4k views

On Visual Studio 2010 the following program #include <iostream> using std::cout; int main() { cout << -2147483646 << '\n'; cout << -2147483647 << '\n'; cout ...
Johan Råde's user avatar
  • 21.7k
10 votes
4 answers
8k views

When I run the following code under Windows7 x64, compiled with GCC of MinGW, the result seems to be underflowed: cout<<-2147483648 ; //Output: 2147483648 but when I assigned it to a integer ...
lichenbo's user avatar
  • 1,049
7 votes
3 answers
8k views

#define SCALE (1 << 31) #define fix_Q31_80(x) ( (int) ( (float)(x)*(float)0x80000000 ) ) #define fix_Q31_SC(x) ( (int) ( (float)(x)*(float)SCALE ) ) int main() { int fix_80 = ...
Danijel's user avatar
  • 8,684
12 votes
1 answer
768 views

My snippet: auto i = -2147483648; int j = 3; std::swap(i, j); // Compile error about mismatched types here. The compiler states that the literal i is a long long. Why is that? -2147483648 fits in an ...
P45 Imminent's user avatar
  • 8,641
6 votes
4 answers
6k views

To extract the upper and lower word of an unsigned 32-bit integer and store each one in separate uint16_t-variables I do as follows (nbr is an unsigned 32-bit integer): uint16_t lower_word = (...
Abdel Aleem's user avatar
1 vote
2 answers
6k views

I'm trying to improve my coding practice for embedded. The code below writes the value 0 to the memory location 0x80001000. #define MemoryWrite(A,V) *(volatile unsigned long*)(A)=(V) #define FLAG ...
riverrock's user avatar
  • 143
6 votes
3 answers
697 views

Since C++20 two's complement representation is the only representation allowed by the standard, with the guaranteed range from -2N-1 to +2N-1-1. So for a 64-bit signed integer type the range goes from ...
user avatar
0 votes
3 answers
2k views

I have predefined HEX values in my code. One of them is in the following. #define ADDRESS1 0xD445556BD557 #define ADDRESS2 0xED612BDF113B I also have an uint8_t array. Like uint8_t MAC[6]; How can ...
Caglayan Dokme's user avatar
7 votes
2 answers
365 views

I have a uint64_t which I need to divide by 1000000. I am working on an embedded system and just doing the division leads to this error: undefined reference to '__udivdi3' I can, however, do 32-bit ...
J. Doe's user avatar
  • 163
0 votes
3 answers
1k views

As an exercise I have to write the following function: multiply x by 2, saturating to Tmin / Tmax if overflow, using only bit-wise and bit-shift operations. Now this is my code: // xor MSB and 2nd ...
Duke's user avatar
  • 416

15 30 50 per page