bit operations with python?

Jason jtveatch at gmail.com
Thu Nov 4 21:47:29 EST 2004


I am going through the Geek Challenges on the Open Source Institute
Website: http://www.osix.net/modules/geek/

The instructions for Level 4 are:

"This challenge requires you to use some of your favourite
mathematical operators, and also get to do simple simple file IO.
Additionally you will learn bit operations.

# download this file. Process every byte, if it is greater than 30
(hex) then add 1 to it. If it is smaller than 2A (hex) then add 2 to
it.

# Reduce the filesize by half by taking every second byte out of the
file (delete the second, the fourth etc). Put the result into
part1.dat.

# Take this file AND (the & operator) each byte with part1.dat. Finish
when any end of file (whichever is first) is reached.

# Put the result into a file called part2.dat.
Take part2.dat and XOR(the ^ operator) each byte of it with its own
value and put the result into a new file called part3.dat.

# Finally take part3.dat and add (+) every byte together, append
_solution to the resulting number, and enter it in the box below."

Is it possible to do this sort of thing with python? If so, could
someone recommend a website with instructions on bit operations?
Thanks!



More information about the Python-list mailing list