MCPcopy Create free account
hub / github.com/ICE27182/Python-3D-renderer / print_bytes

Function print_bytes

png.py:564–585  ·  view source on GitHub ↗

Take bytes type and print a formated string

(bytes:bytes, start:int=0, group_size:int=4)

Source from the content-addressed store, hash-verified

562
563
564def print_bytes(bytes:bytes, start:int=0, group_size:int=4) -> None:
565 """Take bytes type and print a formated string"""
566 # Initiate a list where each element is a string in formate of
567 # index_n+1 ... index_n+group_size | hex_n+1 ... hex_n+group_size
568 output = []
569 # Loop through the bytes in groups of 'group_size'
570 for index in range(len(bytes[start:]) // group_size):
571 output.append("\t".join(str(index * group_size + i + start) for i in range(group_size)) +
572 "\t|\t" +
573 "\t".join(
574 bytes[index * group_size + i + start :
575 index * group_size + i + start + 1].hex().upper()
576 for i in range(group_size)))
577 if len(bytes[start:]) % group_size != 0:
578 # Create a line for the remaining bytes (if any)
579 index += 1
580 output.append("\t".join(str(index * group_size + i + start) for i in range(group_size)) +
581 "\t|\t" +
582 "\t".join(bytes[index * group_size + i + start :
583 index * group_size + i + start + 1].hex().upper()
584 for i in range(len(bytes[start:]) % group_size)))
585 print("\n".join(output))
586
587
588

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected