How to convert two's complement? Calculator program and usage example

3

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!

ssvarc

Posted 2010-02-15T15:31:05.203

Reputation: 720

Question was closed 2010-02-16T16:44:26.273

Can you please tell me how one does that on the built in calculator? Thanks! – None – 2010-02-15T15:33:28.880

2View -> Programmer or Alt + 3 – Robin Day – 2010-02-15T15:34:10.087

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 – 2010-02-15T15:38:42.690

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 – 2010-02-15T16:45:16.173

2

this question is not a duplicate of http://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 – 2010-02-15T17:33:05.043

In which case the OP can post a new question stating exactly that. I single feature or help on how to use something does not make it less then a duplicate. Therefore he asked two separate questions. – BinaryMisfit – 2010-02-17T08:03:26.300

Answers

4

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).

ChrisF

Posted 2010-02-15T15:31:05.203

Reputation: 39 650

1I'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 – 2010-02-15T16:09:03.703

0

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

Jader Dias

Posted 2010-02-15T15:31:05.203

Reputation: 13 660

I'm looking to convert from two's complement to decimal or regular binary. – ssvarc – 2010-02-15T16:14:27.060

@Ssvarc I edited to show how to convert from two's complement – Jader Dias – 2010-02-15T17:32:41.707

@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 – 2010-02-15T17:33:35.747

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 – 2010-02-17T06:49:00.947

@Ssvar I fear I couldn't make myself clear. What I am saying is that bitcmp(bitcmp(x)) is equal to x – Jader Dias – 2010-02-17T14:24:13.543