Python Forum
Unable to bit shift and logical OR bytes and ints?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to bit shift and logical OR bytes and ints?
#8
Nice thing about struct.pack and unpack is it is very easy to fix bytesex problems and you can read/write arrays and structures.

Since struct is the common way to communicate with C/C++ it is going to be around as long as Python. And it is well documented.

As for readability, the shift code reads easier than this?
def header_address(filename):
    '''Return unsigned int value starting at byte 36 in the file header'''
    with open(filename, "rb") as file:
        file.seek(36, 0)
        return struct.unpack('>I', file.read(4))
Reply


Messages In This Thread
RE: Unable to bit shift and logical OR bytes and ints? - by deanhystad - Sep-01-2020, 03:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find a shift between 2 pictures TazFleck 0 1,142 Jan-18-2023, 09:56 PM
Last Post: TazFleck
  Help with Logical error processing List of strings dmc8300 3 1,081 Nov-27-2022, 04:10 PM
Last Post: Larz60+
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,505 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  Convert String of an int array to a Numpy array of ints mdsousa 5 5,670 Apr-08-2021, 08:00 PM
Last Post: mdsousa
  Greedy algorithms on logical problems Opensourcehacker 0 1,532 Nov-22-2020, 05:12 PM
Last Post: Opensourcehacker
  List index out of range error when attempting to make a basic shift code djwilson0495 4 2,986 Aug-16-2020, 08:56 PM
Last Post: deanhystad
  Writing a basic shift code djwilson0495 2 2,254 Aug-16-2020, 01:52 PM
Last Post: djwilson0495
  Basic logical errors cpopescu 3 2,048 Jun-03-2020, 11:30 AM
Last Post: menator01
  Python logical operator AND rasec70 4 2,516 May-07-2020, 03:40 PM
Last Post: pyzyx3qwerty
  Pynput doesn't recognize shift button and special characters VirtualDreamer 0 3,017 Jul-17-2019, 11:55 AM
Last Post: VirtualDreamer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020