What is the text representation of binary data?

Sometimes, when you load a compiled binary with the wrong mime type, or, for example, run the "more" command in a binary, you get a bunch of "manly gook" for lack of a better term.

For example, this is 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 words why this is so? What happens when a text editor or mime plain text type tries to interpret binary data? Does ^ @ mean anything in this context? Why is there some kind of text and some kind of strange hook? Is there any standard for how this binary data is presented in the text? Why is it not just 1s and 0s?

I can conceptually understand ascii or unicode as a representation of characters in a number system that can be reduced to binary 1 and 0 and a number system that the CPU understands. But at a higher level, I'm trying to understand what binary data is. I think I want to "see the abstraction," if that makes sense.

Is there a way to “see” binary data in any meaningful way in a text editor?

+3
8

, , . ( ) (ASCII, ANSI).

"^ @", 0 ( nul). Nul- , .

, , . Mac, http://hexedit.sourceforge.net/.

/ , , , .

: re: ^ @.

+4

- , - 0 1. , , , .
() 0 1 , , . , , , , ASCII. , , ASCII. , , , ( ).
Hex- - , ( ). ASCII-, , .
, - , google " " , .

+3

"" ?

! , VIM...:

XXD

: , . Vim "xxd" . . :

vim -b

xxd:

:% XXD

:

0000000: 1f8b 0808 39d7 173b 0203 7474 002b 4e49  ....9..;..tt.+NI      
0000010: 4b2c 8660 eb9c ecac c462 eb94 345e 2e30  K,.`.....b..4^.0      
0000020: 373b 2731 0b22 0ca6 c1a2 d669 1035 39d9  7;'1.".....i.59. 

. Vim . . , :

:%! xxd -r

. .

. xxd . .

+2

od Unix. , . , od -c file.

LE: GNU od (1) man page

+1

"" ?

, . , , . (, .)

Unix/Linux - "" . , " " . , . // .., , "od" ; , , ..

: " ":

  • , () () . , .

  • (, "" ), " ", . , , "magic" script "#!" . , , "#!" , , "" ,

, , , .

. , - , . / . , / . , , .

+1

( ) .

ascii , .

hex/ascii (, od), , , , , .

, , , , .

,

. , . . , .

+1

, . , . : .

, . , 8 ASCII ( 0 255).

( ), . . ( ASCII), , , ASCII.

, . , , ASCII, .

, , ASCII . , : hexidecimal. 4 ​​ , 0 F.

+1

Source: https://habr.com/ru/post/1717542/


All Articles