197

What's a good hex editor/viewer for the Mac? I've used xxd for viewing hexdumps, and I think it can be used in reverse to make edits. But what I really want is a real hex editor.

Mike Akers
  • 12,039
  • 14
  • 58
  • 71

6 Answers6

382

To view the file, run:

xxd filename | less

To use Vim as a hex editor:

  1. Open the file in Vim.
  2. Run :%!xxd (transform buffer to hex)
  3. Edit.
  4. Run :%!xxd -r (reverse transformation)
  5. Save.
cambunctious
  • 8,391
  • 5
  • 34
  • 53
Ayman Hourieh
  • 132,184
  • 23
  • 144
  • 116
  • 1
    There also [vinarise.vim](https://github.com/Shougo/vinarise.vim) plugin which makes hex editing workflow nicer. –  Jan 06 '15 at 23:23
  • 8
    This is exactly why I ask candidates "teach me something I don't know about vim" in every interview. After 15 years I'm still find GOLD. – Bruno Bronosky Jan 06 '16 at 01:33
  • 52
    If you understand what `:% !` does, then you will realize this is equivalent to doing `cat filename.bin | xxd`. So really this is more of a "did you know that you have an `xxd` command?" answer. Now that I look into it, I find that xxd also accepts a filename. So, if you only need to see the content of the binary/hex file, you can just use `xxd filename.bin`. Good stuff! – Bruno Bronosky Jan 06 '16 at 01:37
  • 4
    The problem with using xxd (and with using vim as described in this answer) is that there's no highlighting of the char and binary value. You'll need to count more characters and remember more positions to use this "dumb" binary dump effectively. Also, there's no intelligent analysis of endianness or interpretation of byte ranges as different types. – piojo Nov 17 '16 at 04:02
  • 6
    @BrunoBronosky Or `xxd filename.bin | less` when it doesn't fit in one screen height. – Derek 朕會功夫 Nov 22 '16 at 05:00
  • @Derek朕會功夫 and `reset` when you forget to pipe to `less` and your terminal is hosed from the control characters. ;-) – Bruno Bronosky Nov 22 '16 at 05:27
  • 1
    when i did this vim added a trailing newline, i did `set :binary` and `:set noeol` – lamont Mar 12 '17 at 21:11
  • I found that in the situation the file is with all "0x00", xxd is not working: % xxd file1 xxd: Operation timed out % xxd --version xxd 2022-01-14 by Juergen Weigert et al. % echo $SHELL /bin/zsh It's MacOS Monterey 12.4. The problem is you don't know that (all "0x00" situation) if xxd doesn't work. – ywu Nov 01 '22 at 20:24
128
  1. Open file with Xcode and press Command + Shift + J
  2. Right click file name in left pane
  3. Open as -> Hex
crizCraig
  • 8,487
  • 6
  • 54
  • 53
87

One recommendation I've gotten is Hex Fiend.

Mike Akers
  • 12,039
  • 14
  • 58
  • 71
  • Yea, and you can read the developer talking about fun implementing stuff on it here http://ridiculousfish.com/blog/ – kch May 06 '09 at 00:50
  • 5
    Also like Hex Fiend. The project moved to GitHub - so download the latest version on the releases tab instead of their previous website - https://github.com/ridiculousfish/HexFiend/releases – cwd Mar 18 '16 at 18:48
  • 4
    It's also available on Homebrew: `brew cask install hex-fiend` – pyb Jul 16 '18 at 18:25
24

I have recently started using 0xED, and like it a lot.

mschmidt
  • 2,740
  • 4
  • 17
  • 31
pgb
  • 24,813
  • 12
  • 83
  • 113
  • @JarretHardie HexFriend does not support dragging I suppose? – daisy Jan 18 '15 at 07:50
  • 0xED seems to be the most simple and user-friendly of the free options out there. Just download and run, and get a side-by-side hex/ASCII view. Text editors work too, but often don't have very good binary-level editing/display options. Plus 0xED is incredibly fast; you can browse in realtime through a 1 GB file. – Beejor Sep 29 '18 at 16:51
  • 0xED doesn't work at all for me (it doesn't even show a UI). macOS Mojave. I also find it fishy that there's no checksum posted on the site for the latest version. – tony19 Sep 23 '19 at 05:51
  • 1
    According to the official site, 0xED is no longer under active development – Felipe Sabino Mar 02 '20 at 16:29
  • At some point in the last year the official website went offline (domain renewed in May 21). You can still find the last release in archive.org's wayback machine. However this project isn't open source and as the developer/site is gone...so you are probably better off adopting a different tool (`xxd`, hexfiend, xcode, etc). – mattpr Nov 26 '21 at 13:01
11

There are probably better options, but I use and kind of like TextWrangler for basic hex editing. File -> hex Dump File

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • 1
    TextWrangler has been sunsetted/discontinued as of macOS 10.13 (High Sierra). – Matt Sephton Mar 03 '18 at 00:43
  • 2
    BBEdit is the "replacement" for TextWrangler, looks and feels the same and offers the same features as TextWrangler, and **still free**. You only pay to support the developer and/or unlock more advanced features. https://www.barebones.com/products/textwrangler/ – Hanzaplastique May 30 '18 at 14:14
  • This is exactly the same for the latest version of BBedit – AbsoluteƵERØ Jun 29 '18 at 16:33
  • 2
    Unfortunately, while BBEdit's free version is essentially the same, it has some notable differences from TW, especially the addition of nag stuff (menu items labeled "Pro" or whatever). TextWrangler still works well if you can grab a download. – Beejor Sep 29 '18 at 16:54
  • Can you **edit** hex in TextWrangler/BBEdit? I have only find a way to **hexdump** and read, not edit and save back to file. – d-b May 03 '23 at 21:28
7

The one that I like is HexEdit Quick and easy to use

twik
  • 71
  • 3
  • How do you compile it? Its Makefile seems corrupted, and even trying to fix it manually didn't seem to work. Can you post a correct Makefile for it? – Alex Jun 29 '17 at 14:51
  • 2
    Even if this source binary was ok, I trust nothing on Sourceforge. – rustyMagnet Mar 12 '18 at 10:45