قالب وردپرس درنا توس
Home / Apple / macos – Why isn't a binary file shown as 0s and 1s?

macos – Why isn't a binary file shown as 0s and 1s?



There are two interpretations of the word binary. While binary in the form of a speech system refers to a base 2 number system (which uses two symbols 0 and 1), for a file, binary refers to a file containing non-textual data (programs, libraries, data files, etc.). A binary file that can be run as a process is usually called an executable binary.

A file that is a binary file does not mean that will appear only in the form of 0 and 1. There are layers of abstractions at work.

Showing a binary file in the form of 0 and 1 will make the output unnecessarily long and is not the most appropriate. A binary file is displayed in a text editor according to the specified default encoding for the editor.

If an editor is configured to display binary output, it will also display each (smoothly clean text) file in the form of 0 and 1

(since everything eventually boils down to binary 0 and 1).

You must use a special editor mode that can display a binary dump of a file. One such way is to run the following command in Terminal:

  xxd -b filename

It will display binary dump of filename on standard output.

A more compact and common screen form is hexadecimal, which uses a base 16 number system (0-9, AF) that can be displayed by just running xxd 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 ......
$ 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 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 ................


Source link