What does \x00 mean in binary file?

85,322

An ASCII file might be read or interpreted as having NULL-terminated strings, carriage returns & line-feeds, or other control characters, that are intended to be read and acted on. For example, a text reader might look for a line of text, where a line is "however many characters you see before you get to a linefeed"

A binary file is considered to be just a sequence of bytes - none of them has any special meaning, in the sens that a text-reader would interpret them.

\x00 is an example of a specific byte value (HEX 0), that might be interpreted in a special way by a text reader.

Share:
85,322
Bagong21
Author by

Bagong21

Updated on May 11, 2020

Comments

  • Bagong21
    Bagong21 almost 4 years

    Once I asked a guy "what is the difference between ASCII and Binary files?"

    And he said "Binary files always have \x00"

    I've been searching about this and found What is the meaning of \x00 , \x04 in PHP

    so the conclusion is, ASCII files don't have NULL character?

  • Bagong21
    Bagong21 almost 13 years
    I found this good website mark0.net/hexdump.html and I uploaded an ASCII file, but I didn't find any NULL character? or maybe the website needs revision :D thanks anyway
  • Aater Suleman
    Aater Suleman almost 13 years
    Just coz that one file didnt have a null doesnt mean NULL is not a part of ASCII. It happens to be the FIRST ASCII character according to ASCII:) cdrummond.qc.ca/cegep/informat/Professeurs/Alain/files/…
  • Aater Suleman
    Aater Suleman almost 13 years
    Good. Then I am confused. I do not understand how you conclude that ASCII files do not have NULL by uploading one file and looking at its content?
  • Bagong21
    Bagong21 almost 13 years
    did you see stackoverflow.com/questions/1182812/… ? it's the link above, on this question
  • Bagong21
    Bagong21 almost 13 years
    I didn't conclude anything, I've searched and tested. did you do that?
  • Aater Suleman
    Aater Suleman almost 13 years
    yes I checked. How does that imply that ascii files don't contain NULLs? Does it say that somewhere?
  • Aater Suleman
    Aater Suleman almost 13 years
    yup. tested, I can write and read an ascii file with a null in there. Hexdump shows the null if you write a null to a file, as expected. It just happens that the file you uploaded didn't have a null. You can write an ascii file using perl/C/python and put a null in there using \0. then open it using the editor of your choice to confirm it works and then upload it to hexdump. dude I studied computers for 10 years, i design them on a daily basis. they are simple devices, not magic. If null is a part of ascii, it can appear in an ascii file (by definition).
  • Schmuddi
    Schmuddi over 6 years
    This is an old answer, but for the record: The generic statement that "ASCII files have NULL characters" is misleading, and the statement "every string in ASCII ends at a NULL" is just wrong. An ASCII file is just a file that contains only ASCII characters. It may or may not contain NULL. NULL has no specific meaning in an ASCII file, and it certainly doesn't act routinely as a termination marker. What is true is that some languages (e.g. C) use NULL to mark the end of a string in RAM. A programmer might decide to use this representation also in a file, but there's no obligation to do so.