Aug-29-2020, 08:02 AM
Python 3.8.2
Windows 10
Powershell
I'm trying to grab a set of 32 bit little-endian pointers from the headers in a set of 256 files, and print them sequentially with line breaks between them.
Here's what it prints when I comment out the lines with bit shifting and logical OR.
Windows 10
Powershell
I'm trying to grab a set of 32 bit little-endian pointers from the headers in a set of 256 files, and print them sequentially with line breaks between them.
import sys,glob def printFileAddr(fileName): with open(fileName,"rb") as file: file.seek(36,0) address = file.read(1) address = ((file.read(1) << 8) | address) address = ((file.read(1) << 16) | address) address = ((file.read(1) << 24) | address) print(str(address) + "\n") for arg in sys.argv[1:]: for files in glob.glob(arg): printFileAddr(files)Output
PS C:\Users\pc\Projects\romhack\sagaFrontier\scripts> python .\printArc.py .\M000.ARC Traceback (most recent call last): File ".\printArc.py", line 14, in <module> printFileAddr(files) File ".\printArc.py", line 7, in printFileAddr address = ((file.read(1) << 8) | address) TypeError: unsupported operand type(s) for <<: 'bytes' and 'int' PS C:\Users\pc\Projects\romhack\sagaFrontier\scripts>1. Why doesn't Python allow one to bitshift numbers? Why have bitwise operators if you can't use them?
Here's what it prints when I comment out the lines with bit shifting and logical OR.
PS C:\Users\pc\Projects\romhack\sagaFrontier\scripts> python .\printArc.py .\M000.ARC b'`'2. Why is it not printing the numeric value of the byte?