#!/usr/bin/env python
#--coding:utf-8
import sys
import os
import socket

def Proc(SrcFileName, DestFileName):
    srcFileHandle = open(SrcFileName, 'rb')
    destFileHanel = open(DestFileName, 'wb')
    srcFileHandle.seek(0, 0)
    print "now seek = %s" % (srcFileHandle.tell(), )
    srcFileHandle.seek(0, 2)
    fileLen = srcFileHandle.tell()
    print "fileLen = %s" % (fileLen, )
    print "now seek = %s" % (srcFileHandle.tell() , )
    srcFileHandle.seek(0, 0)
    print "now seek = %s" % (srcFileHandle.tell(), )
    print "文件长度为 ", fileLen
    if ((fileLen % 4) != 0):
        print "长度不为4的整倍数 有问题"
        return

    try:
        while True:
            chunk = srcFileHandle.read(4)
            if (not chunk):
                print "end of file"
                break;
            destFileHanel.write(chunk[3])
            destFileHanel.write(chunk[2])
            destFileHanel.write(chunk[1])
            destFileHanel.write(chunk[0])
    finally:
        srcFileHandle.close()
        destFileHanel.close()

if __name__ == '__main__':
    Proc("src.dat", "out.dat")


转换大小端,一时没找到现成的工具
//=====================================================

以下是忘了在哪找的代码了

#include <stdio.h>

int main()
{
    int i = 0x11223344;
    char * a = (char *)&i;
    int j;
    printf("Little Endian:\n");
    for (j = 0; j < 4; j++)
        printf("%x\n", a[j]);
    printf("\n");

    i = htonl(i);
    printf("Big    Endian:\n");
    for (j = 0; j < 4; j++)
        printf("%x\n", a[j]);
}

----------------------------------
Little Endian:
44
33
22
11

Big    Endian:
11
22
33
44