You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

23 lines
494 B

  1. # coding: utf-8
  2. from __future__ import unicode_literals, division, absolute_import, print_function
  3. def fill_width(bytes_, width):
  4. """
  5. Ensure a byte string representing a positive integer is a specific width
  6. (in bytes)
  7. :param bytes_:
  8. The integer byte string
  9. :param width:
  10. The desired width as an integer
  11. :return:
  12. A byte string of the width specified
  13. """
  14. while len(bytes_) < width:
  15. bytes_ = b'\x00' + bytes_
  16. return bytes_