I have two codes in C and in Python.
They gave me different results.
Can anybody explain how they works, why I get different results?
Thank you in advance!!!

In C:
-----------
#include <stdio.h>
int main()
{
int a = 100;
printf("%d = %02x\n", a, a);
a = ~a;
printf("%d = %02x\n", a, a);
return 0;
}

OUTPUT:
100 = 64
-101 = ffffff9b

In Python:
-----------
a = 100
print("%d = %02x"%(a,a))
a = ~a
print("%d = %02x"%(a,a))

OUTPUT:
100 = 64
-101 = -65

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.