How can I convert hexadecimal to decimal numbers in Emacs calc?
For example, if I enter FF
, I want it to convert it to 255
.
UPDATE: How do I get the reverse operation, turn base 10 to base 16?
You can enter any number in the format <base>#<number>
. Example: 16#FF
is immediately converted to 255
.
For the reverse, you need to set the output display mode. In this example, d
r
16
RET sets the display to base 16. Set it to base 10 to get the default behaviour again.
By the way, you can also Read The Fine ManualTM: GNU Emacs Calc Manual.
Svante answered your question, but I'd like to add that the Radix Display Mode change has a quicker keystroke:
d
6
d
0
Of course you could type 16#FF
to enter 0xFF
, but there is a more convenient way.
The other option:
d 6
#
like #FF
and <enter>
. (The #
means interpret number with given display radix)d 0
.Note: A number entered without #
always inserts a decimal number.
Note2: This also works the other way round.
Negative Values: Now lets say you have a 8-bit system and you want to know how decimal -3 is stored in this systems RAM.
b w 8
3 n
and <enter>
O d 6
. (The O
as Option is important to enable two's complement.)Note: you see 16##FD
. Two #
means it is signed and the value stored in RAM is 0xFD
The above stuff works also with d 2
, d 8
(as shortcuts for bin and oct) and other possible display radixes from 2 to 36 (d r <radix-number>
).
This info is taken from the Emacs Calc Manual.