Big-Endian与Little-Endian的转换

上周用vtk的时候,我自己机器写的数据要传到sgi的机器,要进行Big-Endian与Little-Endian的转换,结果出错了,不知道怎么回事,今天查了一下vtk的源代码,发现他的转换也是这样的按部就班:

inline void
vtkByteSwap::Swap2Bytes(char* &data)
{
  char one_byte; 
  one_byte = data[0]; data[0] = data[1]; data[1] = one_byte;
}

inline void
vtkByteSwap::Swap4Bytes(char* &data)
{
  char one_byte;
  one_byte = data[0]; data[0] = data[3]; data[3] = one_byte;
  one_byte = data[1]; data[1] = data[2]; data[2] = one_byte;
}

inline void
vtkByteSwap::Swap8Bytes(char* &data)
{
  char one_byte;
  one_byte = data[0]; data[0] = data[7]; data[7] = one_byte;
  one_byte = data[1]; data[1] = data[6]; data[6] = one_byte;
  one_byte = data[2]; data[2] = data[5]; data[5] = one_byte;
  one_byte = data[3]; data[3] = data[4]; data[4] = one_byte;
}

阅读更多

没有更多推荐了,返回首页