How can I convert hexadecimal to decimal numbers in calc of Emacs?

Viewed 10989

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?

3 Answers

Svante answered your question, but I'd like to add that the Radix Display Mode change has a quicker keystroke:

  • Show in hexidecimal mode: d 6
  • Show in decimal mode: d 0

Of course you could type 16#FF to enter 0xFF, but there is a more convenient way.

The other option:

  1. change the display radix to hex with d 6
  2. then enter all the hex numbers you want by prefixing them with a # like #FF and <enter>. (The # means interpret number with given display radix)
  3. After this, change the display radix back to decimal with 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.

  1. switch word size: b w 8
  2. enter dec -3 by typing 3 n and <enter>
  3. set display radix to hex with two's complement notation: 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.

Related