Created
November 14, 2017 19:46
-
-
Save MiCurry/3b94e0bddbc59099ba95871705a275c1 to your computer and use it in GitHub Desktop.
Compare two one line files bit by bit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import argparse | |
def tobits(s): | |
result = [] | |
for c in s: | |
bits = bin(ord(c))[2:] | |
bits = '00000000'[len(bits):] + bits | |
result.extend([int(b) for b in bits]) | |
return result | |
def frombits(bits): | |
chars = [] | |
for b in range(len(bits) / 8): | |
byte = bits[b*8:(b+1)*8] | |
chars.append(chr(int(''.join([str(bit) for bit in byte]), 2))) | |
return ''.join(chars) | |
parser = argparse.ArgumentParser(description='Easy way to produce plots of\ | |
3D vector fields in python.') | |
parser.add_argument("files", nargs = 2, | |
help='Two Files to compare', | |
type=str) | |
args = parser.parse_args() | |
f_1 = open(args.files[0], 'r') | |
f_2 = open(args.files[1], 'r') | |
bitString1 = tobits(f_1.readline()) | |
bitString2 = tobits(f_2.readline()) | |
same = 0 | |
diff = 0 | |
length = len(bitString1) | |
for i in range(len(bitString1)): | |
if bitString1[i] == bitString2[i]: | |
same += 1 | |
else: | |
diff += 1 | |
print "Bits the same: ", same | |
print "Bits different: ", diff | |
print "Percent Differnet: ", float(diff) / float(length) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment