How to view and edit Binary files in Visual Studio Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
3 min

banner

# How to view and edit Binary files in Visual Studio Code

Microsoft developed a Hex editor VS Code extension that can be used to view and edit binary files.

You can install the extension by:

  1. Clicking on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux
    • Command + Shift + X on macOS
  1. Typing Hex Editor.

vscode install hex editor extension

  1. Clicking on the Install button.

Make sure to install the Hex Editor extension that was developed by Microsoft as shown in the code sample.

# Opening a binary file in Visual Studio Code

To open a binary file:

  1. Right-click on the file and click on Open With....

open file with

  1. Click on Hex Editor.

click hex editor

An alternative way to open a file is to:

  1. Select the binary file.
  2. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Hex editor and select Hex editor: Open active file in Hex Editor.

open active file in hex editor

Once you open the file, you will be able to view the binary data and the decoded text.

view binary file

If you click on a specific cell, more detailed information is shown.

view detailed information

# Editing a Binary file in Visual Studio Code

You can edit the binary file by selecting a specific cell and typing a new value.

edit binary file vscode

You can save the changes with:

  • Ctrl + s on Windows and Linux.
  • Command + s on macOS.

If you need to switch to the default text editor:

  1. Type Reopen editor and select View Reopen Editor With:.

reopen editor with

  1. Select Text Editor.

select text editor

The hex editor supports opening various files, e.g. text files, images, binary (.bin) files, etc.

# Setting the Hex editor as the default editor for specific files

You can also set the Hex editor as the default editor for certain file types by editing your settings.json file.

You can open your settings.json file by:

  1. Pressing Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Typing settings.json.

set hex editor as default

  1. Clicking on Preferences: Open User Settings (JSON)

For example, the following lines of code set the hex editor as the default editor for files with .hex or .ini extensions.

settings.json
"workbench.editorAssociations": { "*.hex": "hexEditor.hexedit", "*.ini": "hexEditor.hexedit" },

editing setting json

# Supported features

The hex editor supports:

  • Opening files as hex.
  • Viewing the hex values as different data types.
  • Editing with undo, redo, copy and paste support.
  • Find and replace functionality.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.