#! /usr/bin/python # # Program to determine which bits in a 32-bit string have changed import sys def countones(l): s = 0 for i in range(32): if l[i] == '1': s += 1 return s def chomp(l): s = "" for i in range(32): s += l[i] return s def negchomp(l): s = "" for i in range(32): if l[i] == '0': s += '1' else: s += '0' return s def to_bin(v): r = [] for i in range(32): if v&01 == 1: r.append('1') else: r.append('0') v >>= 1 r.reverse() return r # # read in a hex number, convert to bits, and look for a match # # mask is the set of bits we are intersted in mask = 0xFFFFFFFF # care only about low-order bits (32 here) last = None # last one we read changed = to_bin(0x0) # 0 if bit has not changed, 1 if it has for l in sys.stdin: # we just want the number a = int(l.strip(),16) # it's a number -- only care about the low-order bits a &= mask # now xor the bits # last is the previous value # change is the vector showing what bits have changed # initially, make laat be cur and skip check cur = to_bin(a) if last == None: last = cur else: for i in range(32): if last[i] != cur[i]: changed[i] = "1" last = cur print " Changed: ", chomp(changed), countones(chomp(changed)), "changing bits" print "Consistent: ", negchomp(changed), countones(negchomp(changed)), "fixed bits"