Calc Mode 2: Two’s Complement

Emacs provides a method for working out numbers in two’s complement form

M-x calc        Turn on calc mode
O d2            Turns on two's complement binary
b w 8           Sets the word length to 8 bits
d z             Displays leading zeroes

Now you can enter numbers. Don’t forget to use underscore for negative numbers

_3 (-3) gives 2##11111101

You can press y to yank the result back into the last buffer.

Quick Conversions

if you want to quickly convert between binary, denary and hex you can use quick calc mode:
To convert 17 from Denary to Binary

C-x * q         Enter quick calc mode
17              Hit enter
Result: 17 =>  17  (16#11, 8#21, 2#10001, "")

To convert 1100 from Binary to Denary (or Hex)

C-x * q         Enter quick calc mode
2#1100          Enter in minibuffer.  Use 16# to enter a Hex number
Result: 12 =>  12  (16#C, 8#14, 2#1100, "")

See Also

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.