bit manipulation - what is the correct way to process 4 bits inside an octet in python -


I am writing an application to parse some network packet in a packet field, the protocol version number is in octet, so 4 high bits are 'major' and less 4 'minor' versions are. Currently I am parsing them in the following way, but I am thinking that there is a superb or more 'python' method of doing this:

  v = ord (data [17]) = (V & amp;; int ('11110000', 2)) & gt; & Gt; 4 small = V and amp; Int ('00001111', 2)  

You can type binary written words like this For your example, I want to use Hex

  v = ord (data [17]) key = (v)  0b1111000  

& Amp; 0xF0) & gt; & Gt; 4 minor = (V and 0x0 F)

You may also want to use the module to break the packet into its components


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -