Sublime Forum

Binary / Hex possible?

#1

I am working with small binary files which, when opened in ST3, appear in the editor as:

22fc 6b0c 6c3f 6d0c a2ea dab6 dcd6 6e00
22d4 6603 6802 6060 f015 f007 3000 121a

Saving the file effectively converts it to ASCII text, which is okay for what I want. Is there, however, a command that will save the text back to its original binary format? I was hoping that “File|Save with encoding” would do the trick but I wasn’t able to get it to work.

Any suggestions? Is it possible to edit binary data directly in ST3? Thanks.

0 Likes

#2

Not in ST. If you are on Linux (not sure about Mac), you can

  • convert file to hex: xxd -ps "BIN_FILE" "HEX_FILE"
  • convert hex to file: xxd -r -ps "HEX_FILE" "BIN_FILE" (this is what you want)

Plus, an awesome online hex editor https://hexed.it

0 Likes

#3

Maybe helpful?

https://packagecontrol.io/packages/HexViewer

0 Likes

#4

That works great, thank you. I had tried xxd before but I got the options wrong – thanks for that too. Yes, I run Linux. I will look at the hex editor – I trashed some files accidentally by opening and saving in ST, so a good hex editor will be useful.

0 Likes

#5

I’ll try it. Thanks for the tip.

0 Likes

#6

Available on the command line in macOS and linux:

od (octal dump)
od -c (escaped characters)
od -x (hex short ints)
od -X (hex long ints)

man od (for lots more help)

0 Likes