0

If I use a file comparison tool like fc in Windows, you can choose between ASCII and binary comparison.

What is the actual difference between these two comparisons? If I compare two ASCII files, don't I want the binary data of the files to be identical?

CJ7
  • 22,579
  • 65
  • 193
  • 321
  • I'm not confident enough to submit an answer, but it may have to do with how the comparison program interprets newlines in its comparison. – clemej Feb 11 '16 at 02:07
  • This may be the answer. From the `fc` documentation: `/l : Compares the files in ASCII mode. Fc compares the two files line by line and attempts to resynchronize the files after finding a mismatch.` – CJ7 Feb 11 '16 at 02:40
  • Yeah that's it then. Linux uses binary '\n' for newlines, windows uses '\r\n' .. A binary comparison would fail since they are different but a line by line comparison that interprets both as 'end of line' could succeed. – clemej Feb 11 '16 at 02:45
  • Well, I guess more generally , in binary mode its doing a bit for bit comparison over the whole file, but in ASCII mode its doing a line by line comparison, interpreting a newline and potentially ignoring other control characters. – clemej Feb 11 '16 at 02:54

1 Answers1

0

WARNING: this is 5 year old loose remembrance of knowledge from uni

Binary representation means you compare the binary exactly, and ascii is a comparison of data type. to put it in a simple case the char 'A' is a representation of 01000001, but that is also an 8 bit integer equal to '65', so that means A = 65 in binary. so if you were doing A + A as a string and 65 43 65 (43 is '+' in binary to decimal), in binary they would be equivalent, but in ascii they would not. This is a very loose explanation and i'm sure i missed a lot, but that should sum it up loosely.

In a text file you want ASCII because you write in ascii characters. In say, a program state saved to a file you want binary to get a direct comparison.

Byren Higgin
  • 552
  • 4
  • 13
  • But wouldn't two identical ASCII files also have identical binary data? – CJ7 Feb 11 '16 at 02:37
  • another example, the number '0' is represented as `00110000` and '1' as `00110001` in ASCII, not as `00000000` and `00000001` respectively like in binary. therefore the number 10 as ascii would be 00110001 00110000 which is not 00001010 in binary. – Byren Higgin Feb 11 '16 at 03:46