4

I am using emacs with org mode.

Question 1:

I want to number a column in a table in hex. E.g.

| 0x00 | xyz | .. |
| 0x01 | abc | .. |

I want to auto generate first column. Any ideas how to do this in org mode?

Question 2:

How to generate a list of numbers/alphabets etc. (in hex, decimal) in emacs (need not be org mode)?

PS: Please let me know if there are any linux/bash tricks to do this.

NickD
  • 27,023
  • 3
  • 23
  • 42
sakura
  • 143
  • 3

2 Answers2

4

Following is a method using an elisp formula:

| hex  | comment |
|------+---------|
| 0x00 |         |
| 0x01 |         |
| 0x02 |         |
| 0x03 |         |
| 0x04 |         |
| 0x05 |         |
| 0x06 |         |
| 0x07 |         |
| 0x08 |         |
| 0x09 |         |
| 0x0A |         |
| 0x0B |         |
| 0x0C |         |
#+TBLFM: $1='(format "0x%02X" (- @# 2))

format takes a format string much like printf in C.

Then @# gives the current row number, to which I subtract 2 so row 2 displays 0.

Juancho
  • 5,395
  • 15
  • 20
2

This is a partial answer to question 2 -- how generate a list of hex numbers -- based on keyboard macros and calc.

Prepare Calc

Set calc to display in radix 16.

C-x * c d r 16 RET

Optional: Hide the calc buffers by pressing q.

Record a suitable Macro

E.g. do this

f3 f3 M-b C-x * w C-x * w C-e RET f4

Use the Macro

f4 f4 ...

Or do e.g.

C-u 256 f4

Beautification Hint

Search and replace may be used to change the format of the list.

Marco Wahl
  • 2,796
  • 11
  • 13