Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Expanding on Brian's answer:</p> <pre><code># Get rid of the '----' line for simplicity data_file = '''id binary-coded-info 4657 001001101 4789 110111111 ''' import cStringIO import csv, sys data = [] # A list for the row dictionaries (we could just as easily have used the regular reader method) # Read in the file using the csv module # Each row will be a dictionary with keys corresponding to the first row reader = csv.DictReader(cStringIO.StringIO(data_file), delimiter=' ', skipinitialspace = True) try: for row in reader: data.append(row) # Add the row dictionary to the data list except csv.Error, e: sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) # Do something with the bits first = int(data[0]['binary-coded-info'],2) # First bit string assert(first &amp; int('00001101',2) == int('1101',2)) # Bitwise AND assert(first | int('00001101',2) == int('1001101',2)) # Bitwise OR assert(first ^ int('00001101',2) == int('1000000',2)) # Bitwise XOR assert(~first == int('110110010',2)) # Binary Ones Complement assert(first &lt;&lt; 2 == int('100110100',2)) # Binary Left Shift assert(first &gt;&gt; 2 == int('000010011',2)) # Binary Right Shift </code></pre> <p>See the python docs on <a href="http://docs.python.org/reference/expressions.html#binary-arithmetic-operations" rel="nofollow noreferrer">expressions</a> for more information and <a href="http://docs.python.org/library/csv.html#module-csv" rel="nofollow noreferrer">csv module</a> for more information on the csv module.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload