What is the difference between binary and ASCII based file comparison?
Asked Answered
D

1

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?

Diannadianne answered 11/2, 2016 at 1:26 Comment(4)
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.Idolatry
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.Diannadianne
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.Idolatry
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.Idolatry
F
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.

Froissart answered 11/2, 2016 at 1:36 Comment(2)
But wouldn't two identical ASCII files also have identical binary data?Diannadianne
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.Froissart

© 2022 - 2024 — McMap. All rights reserved.