سؤال

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,

هل كانت مفيدة؟

المحلول

In this context, "binary data" is typically just data which could contain null bytes (e.g, '\0'). String manipulation functions like strcpy() and strncpy() will stop when they see these characters, whereas byte manipulation functions like memcpy() and memmove() will always continue for the number of bytes you tell them to.

نصائح أخرى

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

Binary data is just a way of saying that it's data which is not text. In other words, it doesn't actually give you a lot of insight as to what the data is, rather it gives you insight as to what the data isn't.

The odd bit is that, in the most technical sense of the words, text is also binary data.

Binary data is just that, data encoded in binary form. To better view what the contents of a binary file look like, you would need a hex editor like Hiew Editor for Windows or hexedit for linux.

It's all ones and zeros. But the ones and zeros live differently on your computer. The CPU sees the ones and zeros differently from DRAM and both of these are differently encoded in the hard drive.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top