Skip to content

Instantly share code, notes, and snippets.

@rhyolight
Created May 3, 2017 15:29
Show Gist options
  • Save rhyolight/a55e84fa3bd8adb6366f40e9080afdf9 to your computer and use it in GitHub Desktop.
Save rhyolight/a55e84fa3bd8adb6366f40e9080afdf9 to your computer and use it in GitHub Desktop.
example usage
def formatBits(width, desc, inarray, outarray, scale=1, blank=255, leftpad=0):
"""
Copy one array to another, inserting blanks between fields (for display).
If ``leftpad`` is one, then there is a dummy value at element 0
of the arrays, and we should start our counting from 1 rather than 0.
:param inarray: TODO: document
:param outarray: TODO: document
:param scale: TODO: document
:param blank: TODO: document
:param leftpad: TODO: document
"""
description = desc + [("end", width)]
print description
# copy the data, but put one blank in between each field
for i in xrange(len(description) - 1):
start = description[i][1]
end = description[i+1][1]
print "Copying: %s" % inarray[start:end]
outarray[start+i+leftpad:end+i+leftpad] = inarray[(start+leftpad):(end+leftpad)] * scale
if end < width:
outarray[end+i+leftpad] = blank
if __name__ == "__main__":
input = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0]
desc = [('test formatBits 1', 0), ('test formatBits 2', 3)]
width = len(input)
output = []
formatBits(width, desc, input, output, scale=1)
print output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment