Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question

migrated from stackoverflow.com Feb 15 '10 at 15:36

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Gnoupi, Diago Feb 16 '10 at 16:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Can you please tell me how one does that on the built in calculator? Thanks! –  ssvarc Feb 15 '10 at 15:33
2  
View -> Programmer or Alt + 3 –  Robin Day Feb 15 '10 at 15:34
    
I'm looking at the programmers view and I saw this calculator before I posted. I don't see here how to do coversions to/from twos complement and I would appreciate some specific help. Thanks! –  ssvarc Feb 15 '10 at 15:38
1  
@ssvarc - Your question has been migrated here, where it is more adapted. To regain ownership over your question, you should associate your Super User account with your Stack Overflow one in user options. When done, I recommend you to edit your question according to your last comment. Because if your question remains the generic "looking for calculator program", then we have a duplicate here, and your question will be closed. –  Gnoupi Feb 15 '10 at 16:45
2  
this question is not a duplicate of superuser.com/questions/21950/what-super-calculator-do-you-use -- while some of those tools might have the feature requested, this question also asks how to use that feature. please do not close this as a duplicate. –  quack quixote Feb 15 '10 at 17:33
show 1 more comment

2 Answers

The standard calculator has this built in.

Select View > Programmer (Alt + 3).

From PlanetMath:

Additionally, negative numbers are shown in two's complement (and the sign change key performs two's complement on the displayed value).

share|improve this answer
    
I'm looking at the programmers view and I saw this calculator before I posted. I don't see here how to do coversions to/from twos complement and I would appreciate some specific help. Thanks! –  ssvarc Feb 15 '10 at 16:09
1  
@Ssvarc - BTW - link your SO and SU accounts to regain ownership of the question. –  ChrisF Feb 15 '10 at 16:17
add comment

There are 2 free scripting languages that are good calculators too:

  1. Octave http://www.gnu.org/software/octave/download.html
  2. Python http://www.python.org/

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

share|improve this answer
    
I'm looking to convert from two's complement to decimal or regular binary. –  ssvarc Feb 15 '10 at 16:14
    
@Ssvarc I edited to show how to convert from two's complement –  Jader Dias Feb 15 '10 at 17:32
    
@Ssvarc the inverse operation of the two's complement is itself. So if you seek to convert to or from is the same thing –  Jader Dias Feb 15 '10 at 17:33
    
I still don't follow. Sorry. If what your trying to say is that a two's complement number and it's counterpart in regular binary is the same, then no, that is not correct. (I see that you realize this based on your examples above, so obviously there is something missing here.) –  ssvarc Feb 17 '10 at 6:49
    
@Ssvar I fear I couldn't make myself clear. What I am saying is that bitcmp(bitcmp(x)) is equal to x –  Jader Dias Feb 17 '10 at 14:24
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.