In my Mac OS, we know the files under /bin
all are binary files.:
crafts-MBP:bin ldl$ pwd
/bin
crafts-MBP:bin ldl$ ls
[ csh ed launchctl mv rmdir tcsh
bash date expr link pax sh test
cat dd hostname ln ps sleep unlink
chmod df kill ls pwd stty wait4path
cp echo ksh mkdir rm sync zsh
When I open it using vi
editor:
crafts-MBP:bin ldl$ vi ps
Ïúíþ^G^@^@^A^C^@^@<80>^B^@^@^@^P^@^@^@°^F^@^@<85>^@ ^@^@^@^@^@^Y^@^@^@H^@^@^@__PAGEZERO^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^Y^@^@^@(^B^@^@__TEXT^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@`^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@`^@^@^@^@^@^@^G^@^@^@^E^@^@^@^F^@^@^@^@^@^@^@__text^@^@^@^@^@^@^@^@^@^@__TEXT^@^@^@^@^@^@^@^@^@^@P^V^@^@^A^@^@^@\;^@^@^@^@^@^@P^V^@^@^B^@^@^@^@^@^@^@^@^@^@^@^@^D^@<80>^@^@^@^@^@^@^@^@^@^@^@^@__stubs^@^@^@^@^@^@^@^@^@__TEXT^@^@^@^@^@^@^@^@^@^@¬Q^@^@^A^@^@^@<92>^A^@^@^@^@^@^@¬Q^@^@^A^@^@^@^@^@^@^@^@^@^@^@^H^D^@<80>^@^@^@^@^F^@^@^@^@^@^@^@__stub_helper^@^@^@__TEXT^@^@^@^@^@^@^@^@^@^@@S^@^@^A^@^@^@®^B^@^@^@^@^@^@@S^@^@^B^@^@^@^@^@^@^@^@^@^@^@^@^D^@<80>^@^@^@^@^@^@^@^@^@^@^@^@__const^@^@^@^@^@^@^@^@^@__TEXT^@^@^@^@^@^@^@^@^@^@ðU^@^@^A^@^@^@P^A^@^@^@^@^@^@ðU^@^@^D^@^@^@^@^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80>b^@^@^A^@^@^@³!^@^@^@^@^@^@<80>b^@^@^D^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@__common^@^@^@^@^@^@^@^@__DATA^@^@^@^@^@^@^@^@^@^@8<84>^@^@^A^@^@^@@^@^@^@^@^@^@^@^@^@^@^@^C^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@__bss^@^@^@^@^@^@^@^@^@^@^@__DATA^@^@^@^@^@^@^@^@^@^@x<84>^@^@^A^@^@^@^Y^@^@^@^@^@^@^@^@^@^@^@^C^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^Y^@^@^@H^@^@^@__LINKEDIT^@^@^@^@^@^@^@<90>^@^@^A^@^@^@^@@^@^@^@^@^@^@^@<90>^@^@^@^@^@^@P8^@^@^@^@^@^@^G^@^@^@^A^@^@^@^@^@^@^@^@^@^@^@"^@^@<80>0^@^@^@^@<90>^@^@<90>^A^@^@<90><91>^@^@x^@^@^@^@^@^@^@^@^@^@^@^H<92>^@^@p^D^@^@x<96>^@^@ ^@^@^@^B^@^@^@^X^@^@^@^X<97>^@^@L^@^@^@^P<9e>^@^@ ^C^@^@^K^@^@^@P^@^@^@^@^@^@^@^A^@^@^@^A^@^@^@^A^@^@^@^B^@^@^@J^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@Ø<9b>^@^@<8e>^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^N^@^@^@ ^@^@^@^L^@^@^@/usr/lib/dyld^@^@^@^@^@^@^@^[^@^@^@^X^@^@^@.þLóÎá2^Dªáµ9¦S<8a>+2^@^@^@ ^@^@^@^A^@^@^@^@^N
^@^@^N
you see there shows so many @^
and some English signal, such as: __stub_helper
.
Why it is not shown in terms of 0
and 1
?
Best Answer
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
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