# Using 2's compliment in gcalctool

I would like to convert between negative decimal numbers and two's complement hex and binary (i.e. convert between decimal -1 and hex 0xFFFF in 16-bit mode). Apparently this is possible, as there was a bug report in 2007 dealing with the same issue (https://bugs.launchpad.net/ubuntu/+source/gcalctool/+bug/151676) that was labeled "Invalid" because the operation was possible... But it is still not clear how to do the operation.

## Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gcalctool Edit question
Assignee:
No assignee Edit question
Solved by:
Mike Godin
Solved:
Last query:
 Revision history for this message mycae (mycae) said on 2010-12-20: #1

cant you just compute 2^16-1 by hand?

 Revision history for this message mycae (mycae) said on 2010-12-20: #2

by "hand" i mean by typing that into the calculator :)

 Revision history for this message Mike Godin (godin) said on 2010-12-20: #3

Yes, that does indeed answer the question... but is there a quick way to enter 2^N in "programming mode? I suppose 2 < 15 would do it for 2^16, but what about 2^64 ?

There is a "2's" button that appears in programming mode, but it appears to be completely undocumented. One would expect that to do what I want. By plugging in random numbers, I think I've got it figured out...

X twos Y = X * (twos compliment of |Y|)
Note that if Y is negative, it must be > -[2^{base-12}])

So the answer to my question should probably be:
1 twos 1 = FFFF

Seems to work in 64 bit mode too.
1 twos 81985529216486896 = 1.836e19 = FEDCBA9876543210

 Revision history for this message Sam_ (and-sam) said on 2010-12-20: #4
 Revision history for this message Mike Godin (godin) said on 2010-12-20: #5

Thanks -- I'd missed that part of the manual. However, it seems to be incorrect, as the manual (in versions 5.28 and 5.29) states:

Function: Get the 2's complement
Button: 2's
Description: Calculates the 2's complement for the current value in the display area, using the word size configured in Section 3.6.2 ― To Set the Word Length.
Example: D723 2's
Result: FFFF28DD

Typing "D723 2's" results in a "Malformed Expression" error, at least with version 5.28.2.

 Revision history for this message Sam_ (and-sam) said on 2010-12-20: #6

Mmh, I'm not familiar with programming functions, but since gcalctool lately misses some functions anyway I found qalculate quite useful.

 Revision history for this message mycae (mycae) said on 2010-12-21: #7

>Example: D723 2's
I think this means type "d723" then press the button called "Twos"Example: D723 2's