Why isn't a binary file shown as 0s and 1s?
When dealing with computers, there are two interpretations of the word binary.


In terms of number system, it refers to a base 2 number system which uses two symbols, 0 and 1.
When speaking of a file, it refers to a file containing non-textual data (executables, libraries, data files etc.).


A binary file that can be run as a process is called an executable binary.

A file being binary file doesn't simply mean that it will be displayed simply in terms of 0's and 1's. There are layers of abstractions at work as to how files are handled by a computer.

Showing a binary file in terms of 0 and 1 would make the output unnecessarily lengthy, and is not the most optimal approach. A binary file is shown in a text editor according to the default encoding set for that editor.

Also, if an editor is configured to show binary output, it will also display every file, even plain text ones, in terms of 0's and 1's. Everything ultimately boils down to binary when stored in a computer.

To view a file in the most basic form of 0's and 1's, you'll need to use a special editor mode which is capable of displaying the binary data of a file. One such way is using the built-in xxd command in macOS. Type the following command-line in Terminal:

xxd -b filename

$ xxd -b a.out | head
00000000: 11001111 11111010 11101101 11111110 00000111 00000000  ......
00000006: 00000000 00000001 00000011 00000000 00000000 10000000  ......
0000000c: 00000010 00000000 00000000 00000000 00001111 00000000  ......
00000012: 00000000 00000000 11000000 00000100 00000000 00000000  ......
00000018: 10000101 00000000 00100000 00000000 00000000 00000000  .. ...
0000001e: 00000000 00000000 00011001 00000000 00000000 00000000  ......
00000024: 01001000 00000000 00000000 00000000 01011111 01011111  H...__
0000002a: 01010000 01000001 01000111 01000101 01011010 01000101  PAGEZE
00000030: 01010010 01001111 00000000 00000000 00000000 00000000  RO....
00000036: 00000000 00000000 00000000 00000000 00000000 00000000  ......


It will display the binary dump of filename on standard output. This works equally for both binary and text files.

A more compact and commonly used form, which is preferred over binary is hexadecimal, which uses a base 16 number system (0-9, A-F). To show the contents of file filename in hexadecimal, just run the xxd command without any options with just the filename as argument in Terminal:

xxd filename

$ xxd  a.out | head
00000000: cffa edfe 0700 0001 0300 0080 0200 0000  ................
00000010: 0f00 0000 c004 0000 8500 2000 0000 0000  .......... .....
00000020: 1900 0000 4800 0000 5f5f 5041 4745 5a45  ....H...__PAGEZE
00000030: 524f 0000 0000 0000 0000 0000 0000 0000  RO..............
00000040: 0000 0000 0100 0000 0000 0000 0000 0000  ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 0000 0000 0000 0000 1900 0000 d801 0000  ................
00000070: 5f5f 5445 5854 0000 0000 0000 0000 0000  __TEXT..........
00000080: 0000 0000 0100 0000 0010 0000 0000 0000  ................
00000090: 0000 0000 0000 0000 0010 0000 0000 0000  ................