Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When the OS stores a .txt file (for example), how does it denote whitespace or a newline?

If I'm not mistaken, all data is stored on the hard drive in binary. So is there a certain binary sequence that signals a newline? Or is there a character or characters that signal the OS once the file has been read from binary?

share|improve this question
up vote 3 down vote accepted

Depending on the OS, it uses special characters Linefeed and/or Carriage Return to denote a newline (DOS uses both, Linux uses just Linefeed, and I think, but am not certain that OSX uses just Carriage return).

The characters associated with Carriage return are 0x0D and Linefeed is 0x0A.

share|improve this answer
    
So do linefeed and carriage return characters get stored at the end of the line's binary code? – evamvid Mar 9 '14 at 1:26
    
Yes. Each line in a text file ends with the operating system's representation of newline. (CR, LF, or the two-character CRLF sequence.) With the possible exception of the very last line, which in some cases may be terminated by the end of file rather than having this mark. – keshlam Mar 9 '14 at 5:50
    
OS X uses just Line Feed. Classic Mac OS uses just Carriage Return. – Lukasa Mar 9 '14 at 8:34

You are correct, all data on the hard drive is binary. Text files are stored in binary as well. There is no difference between a text file or movie. Operating systems do know what a text file is and can convert that binary file into human readable form, know as a text file. Windows and *NIX handle text files a little differently, but more or less the same. There are characters that denote end of line, Carriage return, line feed, and End of File.

This Wikipedia article goes into a little more depth.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .