What exactly is the textual representation of Binary data?

binary, text

Solution

There really isn't a significant difference between text and binary files, save for the range of values used within the files. Each value is converted to a character (in a basic text editor) based on the code page used (ASCII, ANSI).

You're seeing the character "^@" because the value of the byte in the file at that position is 0 (the nul character). The nul character is not printable, and so the more program is displaying it using caret notation.

You can open the file in a hex editor, which is a text editor that is more sensitive to binary data. I am not very familiar with Mac software, but a free hex editor can be downloaded at http://hexedit.sourceforge.net/.

Basic text editors/viewers assume that anything you open with it is meant to be read as plain text.

EDIT: Incorporated Mike Spross's corrections re: ^@.

Problem

Sometimes when you download a compiled binary file with the wrong mime type or for example running the "more" command on a binary file you get a bunch of "garbly gook" for lack of a better term. For example this a snippet of what I see when I run "more" from the command line on a very simple C program compiled with gcc on OS X. ``` <94>^^^@^@ESC^@^@^@^^^A^@^@<A8>^^^@^@.^@^@^@^N^D^@^@^P ^@^@@^@^@^@^O^D^@^@^L ^@^@H^@^@^@^O^D^@^@^H ^@^@P^@^@^@^O ^D^@^@^@ ^@^@\^@^@^@^C^@^P^@^@^P^@^@p^@^@^@^O^A^@^@b^_^@^@y^@^@^@^O^D^@^@^D ^@^@<82>^@^@^@^O^A^@^@<B6>^^^@^@<88> ^@^@^@^O^A^@^@T^_^@^@<8D>^@^@^@^O^A^@^@T^^^@^@<93>^@^@^@^A^@^A^B^@^@^@^@<99>^@^@^@^A^@^A^B^@^@^@^@^L^@^@^@^M^@^@ ^@ ^@dyld_stub_binding_helper^@__dyld_func_lookup^@dyld__mach_header^@_NXArgc^@_NXArgv^@___progname^@__mh_execute _header^@_average^@_environ^@_main^@_sum^@start^@_exit^@_printf^@^@^@^@ ``` Can someone explain in simple terms why this is? What is happening when a text editor or the plain text mime type is trying to interpret binary data? Does the ^@ mean anything in this context? Why is there some text and some garbly gook? Is there any standard for the way this binary data is represented in text? Why is it not simple 1 and 0s? I can conceptually understand ascii or unicode as a representation of characters in a number system that can be reduced down to binary 1's and 0 and a number system that the CPU understands. But at a higher level I am trying to get my head around what binary data is. I guess I want to "see the abstraction", if that makes sense. Is there a way to "see" binary data in any kind of meaningful way in a text editor?

Original source