Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6738903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:25:24+00:00 2026-05-26T11:25:24+00:00

Usually, in order to find how two binary files are different, I use diff

  • 0

Usually, in order to find how two binary files are different, I use diff and hexdump tools. But in some situations if two large binary files of the same size are given, I would like to see only their quantitative differences, like number of regions of differences, cumulative difference.

Example: 2 Files A and B. They have 2 diff regions, and their cumulative difference is
6c-a3 + 6c-11 + 6f-6e + 20-22.

File A = 48 65 6c 6c 6f 2c 20 57
File B = 48 65 a3 11 6e 2c 22 57
              |--------|  |--|
                 reg 1   reg 2

How can I get such information using standard GNU tools and Bash or should I better use a simple Python script? Other statistics about how 2 files are different can also be useful, but I don’t know what else and how can be measured? Entropy difference? Variance difference?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:25:25+00:00Added an answer on May 26, 2026 at 11:25 am

    For everything but the regions thing you can use numpy. Something like this (untested):

    import numpy as np
    a = np.fromfile("file A", dtype="uint8")
    b = np.fromfile("file B", dtype="uint8")
    
    # Compute the number of bytes that are different
    different_bytes = np.sum(a != b)
    
    # Compute the sum of the differences
    difference = np.sum(a - b)
    
    # Compute the sum of the absolute value of the differences
    absolute_difference = np.sum(np.abs(a - b))
    
    # In some cases, the number of bits that have changed is a better
    # measurement of change. To compute it we make a lookup array where 
    # bitcount_lookup[byte] == number_of_1_bits_in_byte (so
    # bitcount_lookup[0:16] == [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4])
    bitcount_lookup = np.array(
        [bin(i).count("1") for i in range(256)], dtype="uint8")
    
    # Numpy allows using an array as an index. ^ computes the XOR of
    # each pair of bytes. The result is a byte with a 1 bit where the
    # bits of the input differed, and a 0 bit otherwise.
    bit_diff_count = np.sum(bitcount_lookup[a ^ b])
    

    I couldn’t find a numpy function for computing the regions, but just write your own using a != b as input, it shouldn’t be hard. See this question for inspiration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've checked a satisfying explanation but could not find. Usually docs mention that in
I often use the excellent find program in Bash to list files with certain
Usually, I use SELECT * FROM tableName WHERE fieldName LIKE '%string%' to find every
Usually, when using Windows Authentication, the software (eg Internet Explorer) tries to use Windows
Usually I come across situations where I have to swallow an exception thrown by
I've been doing some reading about two (relatively) new concepts in the Javascript language
Being a programmer I occasionally find the need to analyze large amounts of data
Whenever I have some records/objects that I want to be in a certain order,
I'm trying to parse a large number of short strings into some logical parts.
we have embedded the .NET WebBrowser control (actually two in different tabs, if that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.