linuxbashunixterminalcmp

Does cmp command not use ASCII encoding for bytes?


I read about cmp command at https://www.geeksforgeeks.org/cmp-command-in-linux-with-examples/ and there is a snippet that is bugging me since then.

//...cmp command used with -b option...//

$cmp -b file1.txt file2.txt
file1.txt file2.txt differ: 12 byte, line 2 is 154 l 151 i

/* indicating that the difference is in 12
 byte ,which is 'l' in file1.txt and 'i' in file2.txt.*/

"The values 154 and 151 in the above output are the values for these bytes, respectively."

Why is the value for bytes 154 and 151 for 'l' and 'i'? I would have expected it to be 108 and 105 respectively based on the ASCII system. But these values seem strange to me. Is there any logic for them to appear?

Though this question seems pretty trivial, I could not find an answer for it on Google search. Please help.


Solution

  • Happily, on a GNU system everything is open source, so in doubt you can check the sources. Most probably you are using cmp from diffutils. diffutils cmp.c uses:

            printf (_("%s %s differ: byte %s, line %s is %3o %s %3o %s\n"),
                file[0], file[1], byte_num, line_num,
                c0, s0, c1, s1);
    

    to print the output. The %3o prints the bytes in octal representation.