what is binary data?

ant2009 picture ant2009 · Jun 11, 2011 · Viewed 10.1k times · Source

gcc 4.6.0

What does binary data look like? Is it all 1's and 0's.

I was just wondering, as I was talking to another programmer about copying strings and binary data.

Normally, I use strcpy/strncpy functions to copy strings and memcpy/memmove to copy binary data. However, I am just wondering what does it looks like?

Many thanks for any suggestions,

Answer

jcomeau_ictx picture jcomeau_ictx · Jun 11, 2011

depends on what you're using to view it. here it's in hexadecimal and ASCII:

jcomeau@intrepid:~$ xxd /bin/bash | head -n 10
0000000: 7f45 4c46 0101 0100 0000 0000 0000 0000  .ELF............
0000010: 0200 0300 0100 0000 5021 0608 3400 0000  ........P!..4...
0000020: 345c 0c00 0000 0000 3400 2000 0800 2800  4\......4. ...(.
0000030: 1c00 1b00 0600 0000 3400 0000 3480 0408  ........4...4...
0000040: 3480 0408 0001 0000 0001 0000 0500 0000  4...............
0000050: 0400 0000 0300 0000 3401 0000 3481 0408  ........4...4...
0000060: 3481 0408 1300 0000 1300 0000 0400 0000  4...............
0000070: 0100 0000 0100 0000 0000 0000 0080 0408  ................
0000080: 0080 0408 c013 0c00 c013 0c00 0500 0000  ................
0000090: 0010 0000 0100 0000 c013 0c00 c0a3 1008  ................

here's another way to view it:

jcomeau@intrepid:~$ convert -size 640x$(($(stat -c %s /bin/bash)/640)) \
 -depth 8 gray:/bin/bash /tmp/bash.png
jcomeau@intrepid:~$ firefox /tmp/bash.png

enter image description here