Taeyun
Taeyun

Reputation: 211

Save hexl-mode buffer contents as text in Emacs

there is binary file. containing only 0x42.

In emacs, I can load the file and change buffer to hexl-mode

in the hexl-mode, I can read 0x42 on the left as well as B on the right.

Here, I want to save string displayed on the screen.

If I command C-x C-s, it save as binary file.

How can I save string buffer have?

I want to save "B" as well as "0x42". (please note that 0x42 is not binary 0x42 I want to save "0x42" as string)

I can do this by command

# hexdump binary_file > text.txt

but I want to know the emacs way

help

Upvotes: 1

Views: 679

Answers (1)

phils
phils

Reputation: 73274

You can use write-region to write the hexlified content to a file:

  • C-xh
  • M-x write-region

Alternatively (and especially if you no longer want to edit the buffer in hexl-mode) just change major modes.

e.g. M-x fundamental-mode RET

When you do so, hexl-mode will tidy up after itself by asking you whether or not you wish to convert the buffer back to its binary form.

Answer "No", and you'll end up with the buffer content you wanted (which you can then save).

Upvotes: 3

Related Questions