Python File Hex operations
<p>I am trying to read a hex value like this from a file and do some operations. </p>

<pre><code>REVA: XA0 DID0, DF= Q8B8, Rev: 0.0, UT: 0xd2d32103800600 : Cbos: 18 (0x0)
</code></pre>

<p>I am trying to read UT and do the following operations on it.</p>

<pre><code>x=ut  &amp; 0xFFFFFFFF
y=(ut&gt;&gt;32) &amp; 0xFFFFFF
</code></pre>

<p>My code is below-</p>

<pre><code>f=open('utinfo', 'rb')

for line in f:
    if line.startswith("REVA"):
        ut=line.split()[8] #grabs the value 0xd2d32103800600 
    x   = ut &amp; 0xFFFFFFFF
    y   = (ut&gt;&gt;32) &amp; 0xFFFFFF
</code></pre>

<p>The error I get it is-</p>

<pre><code>     x  = ut &amp; 0xFFFFFFFF
TypeError: unsupported operand type(s) for &amp;: 'str' and 'long'
</code></pre>

<p>So I am reading the value as a string but I thought reading a file as rb would not cause this problem yet it is reading the value as a string. </p>

<p>Btw, this works in python </p>

<pre><code>&gt;&gt;?ut=0x2d32103800600
&gt;&gt;? x=ut &amp; 0xFFFFFFFF
&gt;&gt;?x
0x3800600L
&gt;&gt;? y= ut&gt;&gt;32 &amp; 0xFFFFFF
&gt;&gt;?y
&gt;&gt;?0x0L
</code></pre>

<p>How do I fix this? Thanks a lot for your time &amp; help. </p>
