How to convert two's complement? Calculator program and usage example [duplicate]
Emily Wong
Possible Duplicate:
What super-calculator do you use?
I need a calculator program that runs on Windows 7 that can do two's complement conversions. Specifically convert a two's complement to regular decimal or binary. I'm told that the Win 7 calc does this.
Can anyone give a clear, specific example of how to do this on the built-in calc (or any other freely available program)? Thanks!
62 Answers
The standard calculator has this built in.
Select View > Programmer (Alt + 3).
From PlanetMath:
1Additionally, negative numbers are shown in two's complement (and the sign change key performs two's complement on the displayed value).
There are 2 free scripting languages that are good calculators too:
- Octave
- Python
The solution for two's complement in each of those languages for the number 8923:
Octave
bitcmp(8923, 16)
where 16 is the number of bits in the result
56612
this is because octave only deals with positive numbers in bitwise operations
Python
~8923
results
-8924
To convert from binary to decimal
Octave
bin2dec("10001011011011")
result
8923
To convert from 2' complement to decimal
Octave
bitcmp(bin2dec("10001011011011"), 16)
result
56612
PS: Octave commands are supposed to work in Matlab too
5