求一函数转换little-edian to big-edian(int)等解决办法

求一函数转换little-edian to big-edian(int)等
1。求一函数转换little-edian   to   big-edian(int),
2。求一函数拷贝一个文件的内容到另一个文件。
以上是c++   谢谢了。感激不尽。

------解决方案--------------------
int ltob(int m)
{
int r = 0;
for (i=0; i <32; i++)
{
if (m & (1 < <i))
r |= 1 < < (31-i);
}
return r;
}

void copy(const char* src, const char* dest)
{
ifstream ifile(src, ios::binary);
ofstream ofile(dest, ios::binary);

ifile.seekg(0, ios::end);
int length = ifile.tellg();
ifile.seekg(0, ios::beg);
char* buf = new char[length];

ifile.read(buf, length);
ofile.write(buf, length);

delete [] buf;

ifile.close();
ofile.close();
}
------解决方案--------------------
1.要解决little-edian to big-edian(int)的问题是不按存入内存的方式来存取int值不管是little-edian or big-edian:
char a[2];
short s;
a[0]=(s> > 4)&0xf
a[1]=s&0xf;
这样S值存取方式不变
2.
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

#define BUFSIZE 512
#define PERM 0755

/* copy file function */
int copyfile(const char *name1, const char *name2)
{
int infile, outfile;
ssize_t nread;
char buffer[BUFSIZE];
/* 打开源文件 */
if ((infile = open(name1, O_RDONLY)) == -1)
return (-1);
/* 打开目标文件 */
if ((outfile = open(name2, O_WRONLY|O_CREAT|O_TRUNC, PERM)) == -1)
{
close(infile);
return (-2);
}
/* 循环的把源文件写入目标文件 */
while ((nread = read(infile, buffer, BUFSIZE)) > 0)
{
if (write(outfile, buffer, nread) < nread)
{
close(infile);
close(outfile);
return (-3);
}
}
/* 关闭资源 */
close(infile);
close(outfile);

if (nread == -1)
return (-4);
else
return (0);
}