1

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

1
Contributor
1
Reply
3
Views
6 Years
Discussion Span
Last Post by _neo_
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.