title: byte reverse AB CD to CD AB with python
body: <p>I have a .bin file, and I want to simply byte reverse the hex data. Say for instance @ 0x10 it reads AD DE DE C0, want it to read DE AD C0 DE.</p>
  
  <p>I know there is a simple way to do this, but I am am beginner and just learning python and am trying to make a few simple programs to help me through my daily tasks. I would like to convert the whole file this way, not just 0x10.</p>
  
  <p>I will be converting at start offset 0x000000 and blocksize/length is 1000000.</p>
  
  <p>here is my code, maybe you can tell me what to do. i am sure i am just not getting it, and i am new to programming and python. if you could help me i would very much appreciate it.</p>
  
  <pre><code>def main():
      infile = open("file.bin", "rb")
      new_pos = int("0x000000", 16)
      chunk = int("1000000", 16)
      data = infile.read(chunk)
      reverse(data)
  
  def reverse(data):
      output(data)
  
  def output(data):
      with open("reversed", "wb") as outfile:
          outfile.write(data)
  
  main()
  </code></pre>
  
  <p>and you can see the module for reversing, i have tried many different suggestions and it will either pass the file through untouched, or it will throw errors. i know module reverse is empty now, but i have tried all kinds of things. i just need module reverse to convert AB CD to CD AB.
  thanks for any input</p>
  
  <p>EDIT: the file is 16 MB and i want to reverse the byte order of the whole file.</p>