The goal that I have is to look and see if the operating system is using 2’s complement underlying architecture. Going into this I was at a complete blank after a while I remembered that 1's compliment had two different representations for 0, (0000 0000) and (1111 1111). Now I havnt dealt with binary numbers to this extent within code yet. I was hopping if someone could tell me if this idea will work in telling the differences, if so i could use some hints on how to start writing this code. Thanks
Asked
Active
Viewed 58 times
1 Answers
3
The obvious way to learn about your platform's implementation of types is to print out the object bytes of an object of interest, e.g. a number and its negative:
int a = 5, b = -a;
const unsigned char * p = (const unsigned char *)&a;
const unsigned char * q = (const unsigned char *)&b;
for (size_t i = 0; i != sizeof(int); ++i)
fprintf(stdout, "%02X ", p[i]);
fputc('\n', stdout);
for (size_t i = 0; i != sizeof(int); ++i)
fprintf(stdout, "%02X ", q[i]);
fputc('\n', stdout);

Kerrek SB
- 464,522
- 92
- 875
- 1,084
-
So if i'm understanding this right you use the idea I talked about before, but instead of showing two values for 0. You show that the boundary for twos is 127 to -128, and Ones is 127 to -127? – Cody Syring Feb 21 '17 at 03:26