N
N
Nahs2016-01-25 18:18:01
Python
Nahs, 2016-01-25 18:18:01

How to work with binary data?

There is a sample such lines on Node.js

var header = {};
var offset = 0;
var flags = buf.readUInt8(offset); offset += 1;
header.PRF = (flags & parseInt('11000000', 2)) >> 6;

How to write the same in Python3?
What are the analogues of commands in python?
Which libraries to use: numpy, ctruct?
What can be read on this topic?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
abcd0x00, 2016-01-25
@Nahs

Which libraries to use: numpy, ctruct?

None, it's all done by means of the kernel.
There are even special binary constants
>>> 0b10101 & 0b11 == 1
True
>>>

N
nirvimel, 2016-01-25
@nirvimel

  1. ctypes
  2. struct
  3. Construct [githab] [docs] ( Construct3 )
  4. numpy.recarray aka structured arrays

R
Roman_Kh, 2016-01-25
@Roman_Kh

https://docs.python.org/3.1/library/struct.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question