Two Ways to View a Binary File on Windows Without Installing Anything

Display hexadecimal code and its ASCII equivalent side-by-side


Two Ways to View a Binary File on Windows Without Installing Anything

There are times when you may need to view the contents of a binary file, such as, a file that is either a computer program or a data file. While you can of course look for a free binary or hexadecimal viewer, such a route requires you to download and install a third-party program on the system, something that you may either not want to do (eg, you have limited disk space, or you don't want to take the risk of installing a program from an unknown source) or cannot do (eg, this is a company or client's computer, so you can't just go around installing programs on a whim).

The good news is that you don't actually need to install any third-party program to view binary files. Windows already comes with programs that can take a file (binary or otherwise), and translate it to show hexadecimal code along with its printable (displayable) ASCII equivalent (if any) side-by-side. (Scroll down to see the screenshots if you don't know what I mean.)

Method 1 (Windows 10): Using PowerShell's Format-Hex Cmdlet

This method requires PowerShell 5.0 or above, which comes preinstalled on Windows 10. If you use an earlier version of Windows, see method 2 instead. (You can of course install a newer version of PowerShell on those versions too, but that would negate the whole point of this exercise, which is not to install anything.)

  1. Click the Start menu button and type "powershell" (without the quotation marks). The words "Windows PowerShell" will appear at the top of the menu. Click it.

  2. A window will open, leaving you at a command prompt with something like "PS C:\Users\christopherheng>" just before your text cursor. The actual words following "Users\" will differ, depending on your Windows account name.

  3. Go to the directory containing the file you want to view. You can change directories by typing "cd" followed by the full directory name. For example, if you want to view a file in the "c:\Program Files\Windows Mail" directory, type

    cd "c:\Program Files\Windows Mail"

    If you want to return to the default directory you were in when you first opened PowerShell, type:

    cd $Env:USERPROFILE

    In all cases, after typing the command, you will have to hit the ENTER key before PowerShell will act on your instructions.

  4. In general the command to view a file called (say) "file.exe" is "format-hex file.exe" (without the quotation marks). However, if you do that, and your file is larger than a few bytes or so, the contents will be dumped in one fell swoop onto the screen, scrolling off at great speed, until the entire file has been displayed.

    As such, you will probably want to send the output to a program called "more" which will let you see the contents one screenful at a time. To do that, type the following instead:

    format-hex file.exe | more

    As always, when working on the command line, you will need to type the ENTER key after the command before PowerShell will act on your instructions. If your filename has spaces in it, put quotation marks around it, like this:

    format-hex "c:\Program Files\My Stuff\file to view.exe" | more

    The "|" character, called a "pipe" in this context, sends the output of format-hex as though through a pipe (hence the name) to another program called "more". The latter lets you page forward through the file, one screenful or one line at a time.

    Output of format-hex of a binary file as viewed in more

    To see the next screenful, type the space bar on your keyboard. To scroll up only one line, use the ENTER key. There is no way to scroll back. If you actually need to go back to an earlier screen, one way is to quit the program and redo the command again. To terminate the program before you reach the end of the file (eg, if you have already found what you were looking for, or if you accidentally paged forward past the part you wanted to see and needed to start again), type "q" (without the quotation marks) to quit.

  5. When you are done, close PowerShell by typing "exit" (without the quotation marks), followed by the ENTER key. Alternatively, you can also click the "x" button on the top right hand side of the window in the usual way.

If "More" is Too Limited for Your Needs

While "more" is generally useful for viewing a file one screenful at a time, if you need to page up and down repeatedly, its inability to scroll back can be very frustrating.

In such a case, it may be worth the effort to save the output that "format-hex" produces as a text file, so that you can use a normal plain text editor like Notepad to view it.

To do this, use the following command line instead:

format-hex file.exe > file.txt

This produces a file called "file.txt", which you can open with any text editor. The greater-than sign, ">", causes the output of format-hex to be redirected (ie, saved) into a file named (in our case) "file.txt". You can of course name the file anything you want. Both "file.exe" and "file.txt" are just examples.

Then open "file.txt" (or whatever you called it) in Notepad or another plain text editor. This allows you to page up and down through the output as much as you like.

Method 2 (Windows 7, 8, 8.1, 10): Using Certutil

Windows 7, 8, 8.1, and 10 (I don't know about earlier versions) come with a versatile command line program called certutil which can be used to create a text file containing hexadecimal code alongside their ASCII text equivalent, if any.

Such a text file can then be viewed in any plain text editor, including Notepad, which comes with Windows.

  1. Click the Start menu and type "cmd". The words "Command Prompt" should appear at the top. Click it.

  2. This opens a command prompt window. You should be able to see a blinking text cursor on a line that says something like "C:\Users\christopherheng>". The exact words will be different on your computer, since you are unlikely to have the same Windows account name as me.

  3. Go to the directory containing the file you want to view. You can change directories by typing "cd" followed by the full directory name. For example, if you want to view a file in the "c:\Program Files\Windows Mail" directory, type

    cd "c:\Program Files\Windows Mail"

    If you want to return to the default directory you were in when you first opened Command Prompt, type:

    cd %USERPROFILE%

    In all cases, after typing the command, you will have to hit the ENTER key before Command Prompt will run the program.

  4. To view the contents of (say) "file.exe", we will first get certutil to generate a temporary text file called "file.txt". Actually, you can name the temporary text file anything you want. Just don't give it the same name as an existing file, or certutil will blithely overwrite that file with its output.

    The command to do this is:

    certutil -encodehex file.exe file.txt

    As usual, tap the ENTER key after typing the above line, or nothing will happen. If any of your filenames contain spaces, enclose them in quotation marks, like this:

    certutil -encodehex "c:\Program Files\My Stuff\filename.exe" "temporary output file.txt"
  5. The program "certutil" will then proceed to create the output file. When it's done, you will be deposited back at the command line. Now open that file in Notepad or another plain text editor.

    You can do this either by starting notepad the usual way (eg, typing "Notepad" into the Start menu and clicking the "Notepad" line that appears), then navigating to the location of "file.txt" and opening it, or you can also do it from the command line with:

    notepad file.txt
  6. Since you are viewing it in a text editor, you can scroll up and down the file the normal way you are used to, either with the PgUp and PgDn keys, the scroll bar, or the scroll wheel on your mouse. Note that this is a temporary file that you are viewing, so there's no point trying to edit it or change it. You're going to delete it once you are done viewing it (in the next step).

    Output of certutil of a binary file as viewed in Notepad
  7. When you are done, delete the temporary file if you don't want it any more. You can do this in the usual way with Explorer, or even from the command line by typing "del file.txt".

  8. Close the Command Prompt window by clicking the "x" in the top right hand corner, or by typing "exit" (followed by the ENTER key) on the command line.

Copyright © 2021-2023 by Christopher Heng. All rights reserved. Get more "How To" guides and tutorials from https://www.howtohaven.com/.

This article can be found at https://www.howtohaven.com/system/view-binary-file-on-windows.shtml

howtohaven™ RSS Site Feed

Do you find this article useful? You can learn of new articles and scripts that are published on howtohaven.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at https://www.howtohaven.com/howtohaven.xml.

Please Do Not Reprint This Article

This article is copyrighted. Please do not reproduce this article in whole or part, in any form, without obtaining my written permission.

Related Pages

Newest Pages

How to Link to This Page

It will appear on your page as:

Two Ways to View a Binary File on Windows Without Installing Anything


thesitewizard.com: Free Webmaster Tutorials, Scripts and Articles

thefreecountry.com: Free Programmers' Resources, Free Webmasters' Resources, Free Security Resources, Free Software

HowToHaven.com: Free How-To Guides
If you find this site useful, please link to us.