reorder byte order in hex string (python)

后端 未结 4 1007
再見小時候
再見小時候 2021-01-05 05:17

I want to build a small formatter in python giving me back the numeric values embedded in lines of hex strings.

It is a central part of my formatter and should be re

4条回答
  •  日久生厌
    2021-01-05 05:58

    import binascii, tkinter, array
    from tkinter import *
    
    infile_read = filedialog.askopenfilename()
    
    with open(infile, 'rb') as infile_:
        infile_read = infile_.read()
    
    x = (infile_read)
    y = array.array('l', x)
    y.byteswap()
    swapped = (binascii.hexlify(y))
    

    This is a 32 bit unsigned short swap i achieved with code very much the same as "unutbu's" answer just a little bit easier to understand. And technically binascii is not needed for the swap. Only array.byteswap is needed.

提交回复
热议问题