What does \x00 mean in binary file?
Asked Answered
J

2

47

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?

Johnie answered 10/5, 2011 at 18:18 Comment(3)
That guy either didn't know what the he was talking about or you misunderstood him (that's not an XOR by the way).Dulci
The question should be: What is the difference between a text file and a binary file? An ASCII file is a file containing only bytes with a decimal value in range 0 to 127. That can be a text file or a binary file. PHP is designed for processing text files which can be also files containing characters not present in the ASCII table being character encoded with Windows-1252 or UTF-8 or other encodings.Yttrium
Text files do not contain null bytes in most character encodings. But text files Unicode encoded with UTF-16 or UCS-2 or UTF-32 have lots of null bytes which are not interpreted as null character. For a computer exists only 0s and 1s. How a sequence of 0s and 1s is interpreted by a program is defined by definitions, rules and standards.Yttrium
M
26

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.

Moises answered 10/5, 2011 at 18:28 Comment(0)
S
-3

Wrong. ASCII files have NULL characters. In fact, every string in ASCII ends at a NULL.

ASCII files are files that only contain ASCII characters x0 - x127.

Binary files contain data and each individual byte can be an ascii character, an integer, pointer, etc. Its just how to write data to the file and how you rad it back.

Syphon answered 10/5, 2011 at 18:28 Comment(8)
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 anywayJohnie
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/…Syphon
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?Syphon
did you see #1183312 ? it's the link above, on this questionJohnie
I didn't conclude anything, I've searched and tested. did you do that?Johnie
yes I checked. How does that imply that ascii files don't contain NULLs? Does it say that somewhere?Syphon
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).Syphon
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.Calve

© 2022 - 2024 — McMap. All rights reserved.