[Chennaipy] binary data conversion

Mohamed ali Abdul kkngrmohd at gmail.com
Fri Sep 11 13:11:09 EDT 2020


Hi,
Thanks Mr. Vijay.
I want to convert every 2 bytes of data
The below mentioned code is converting 4 bytes.
Please help me.
Mohamed ali

Code :

import obspy
from array import array
tr= []
#fh = open('header10.txt','wb')
st = obspy.read("/Users/kkngrmohd/Desktop/Stack00007.segy",
unpack_trace_header=False

tr= st[0].stats.segy.trace_header.unpacked_header
print(tr)
arr=array('i')
arr.frombytes(tr)
print(arr)

# tr =b'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x07\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x07\x00\t\x00\x01\x00\x01\x00\x01\x00\x00\x00\x00\x00\x03\xffp\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x9c\xff\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x07\xd0\x07\xd0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17q\x03\xe8\x00\x01\x00\x0c\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\xe4\x00\x80\x00\x0b\x00\x1d\x003\x00\x05\x03\xd2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x039\x99\xdaa\x00\x00\x00\x03\x00\x00\xff\xf6\x00\x00\x00\x00'

### output
#### array('i', [0, 16777216, 117440512, 16777216, 16777216, 0,
117440512, 16779520, 16777472, 0, 1895760640, 0, 0, 0, 0, 0, 0,
-1660969729, 0, 0, 0, 0, -804847360, 53255, 0, 0, 0, 0, 1897332736,
16836611, 3072, 256, 0, 0, 0, 0, 0, 0, 0, -2147425273, 486542080,
83899136, 53763, 0, 0, 0, 0, 0, 0, 0, 50331648, 1641716025, 50331648,
-151060480, 0, 62976, 0, 128, 0, -1660944385])
#### i wanted every 2 bytes data to be converted instead 4 bytes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chennaipy/attachments/20200911/bebf1f97/attachment.html>


More information about the Chennaipy mailing list