Comparing 2 Files?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Comparing 2 Files?

  1. #1
    Join Date
    Nov 2005
    Posts
    281

    Comparing 2 Files?

    Hey I'm trying to compare 2 binaries, like when a project is updated. I want to the comparer to be able to see what % of the bytes are different than from before. Would I be able to do something like comparing a text file? I know the contents of a exe are far different from that of a text, but I'm not entirely sure how I could go about this.

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,060

    Re: Comparing 2 Files?

    You just open both files in binary mode and compare every byte.
    Of course, reading byte per byte is slow, so better is to read a block of bytes, say 256KB into a memory buffer and then compare the memory buffers.

  3. #3
    Join Date
    Nov 2005
    Posts
    281

    Re: Comparing 2 Files?

    Thank you for the help! It cleared everything up for me.

  4. #4
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Comparing 2 Files?

    Comparing the exe contents is not a good idea, reason is, if the exe just have updated for new constant variable string the exe format would push down the stuf and then you would find 90&#37; of difference, but actually only few bytes were added.

    Instead, compare the creation time stamp. Why do you need to compare binaries by the way ?
    Regards,
    Ramkrishna Pawar

  5. #5
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,060

    Re: Comparing 2 Files?

    You are right, but it just depends on how you interpret "difference". When I replied I assumed "difference" meant the real different bytes. So, even if your exe has just an updated constant variable string and pushes 90&#37; of the rest of the exe down, this means that 90% of the bytes are different, even thought they are just move a bit, it's still different.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center