Commit 157d6b81 authored by Gaia Grosso's avatar Gaia Grosso
Browse files

Update main.py

parent dd4f69a1
......@@ -100,7 +100,7 @@ def WriteProperty(device, location, string_mask, write_value):
else: return False
def NBitsAllowed(mask): #string of bits
def NBitsAllowed(mask): #string of bits
output=0
for i in range(32):
if int(mask[i])==1:
......@@ -108,8 +108,8 @@ def NBitsAllowed(mask): #string of bits
print("Number of allowed bits: %i"%(output))
return output
def NBitsNeeded(value): #string of bits
return math.ceil(math.log2(int(value, 2)+1))
def NBitsNeeded(value):
return math.ceil(math.log(value+1, 2))
if __name__ == '__main__':
parser = argparse.ArgumentParser() #Python tool that makes it easy to create an user-friendly command-line interface
......@@ -139,7 +139,7 @@ if __name__ == '__main__':
else:
writevalue = ctypes.c_uint(int(args.value)) #unsigned int (32 bits)
nbits_allowed = NBitsAllowed(bitmask)
nbits_write = NBitsNeeded("{:032b}".format(writevalue.value))
nbits_write = NBitsNeeded(value)
if nbits_write > nbits_allowed:
print("Overflow error! value %s doesn't fit in the allowed memory location."%(args.value))
exit()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment