Mar-05-2018, 03:03 AM
Hello everyone,
This is my first thread in python forum, thank you for reading.
I want to get the 2'complement of an integer, which is the actual representation in the computer. I have tried many methods but failed.Here are some method I tried:
num_a = numpy.int8(-12)
print(format(num_a, 'b'))
print(bin(num_a))
the two outputs are " - 0b10100" and " - 10100 ", instead of "10010011" as I expect. But it is right if the digit is between 0 and 127. Technically , they didn't produce the 2'complement of integer.
By now, I am confused that if the integer is stored in computer using its 2'complement. Is there functions suitable for my question?
I am waiting for your suggestion all the time. Thanks a lot :)
This is my first thread in python forum, thank you for reading.
I want to get the 2'complement of an integer, which is the actual representation in the computer. I have tried many methods but failed.Here are some method I tried:
num_a = numpy.int8(-12)
print(format(num_a, 'b'))
print(bin(num_a))
the two outputs are " - 0b10100" and " - 10100 ", instead of "10010011" as I expect. But it is right if the digit is between 0 and 127. Technically , they didn't produce the 2'complement of integer.
By now, I am confused that if the integer is stored in computer using its 2'complement. Is there functions suitable for my question?
I am waiting for your suggestion all the time. Thanks a lot :)