⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 endian.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
字号:
#include "cdevice.h"

//这个函数是交换两个连续字节的次序
void ByteReversal( unsigned char *s, unsigned char *v )
{
	if( v == NULL || s == NULL )
		return;
		
	s[0] = (unsigned char)( *(v) );
	s[1] = (unsigned char)( *(++v) );
}


//把word转换成byte stream
void Word2Bytes_gfd( unsigned char *s, unsigned short v )
{
	if( s == NULL )
		return;
/*
#ifndef BIG_ENDIAN_ORDER
	s[1] = (unsigned char)( v >> 8 );		// 高字节放高位	
	s[0] = (unsigned char)( v & 0xff );
#else
	s[0] = (unsigned char)( v >> 8 );		// 低字节放高位	
	s[1] = (unsigned char)( v & 0xff );
#endif
*/				////gfd modified for big endian and little endian in 2004.08.19
#ifdef BIG_ENDIAN_ORDER
	s[1] = (unsigned char)( v >> 8 );		// 高字节放高位	
	s[0] = (unsigned char)( v & 0xff );
#else
	s[0] = (unsigned char)( v >> 8 );		// 低字节放高位	
	s[1] = (unsigned char)( v & 0xff );
#endif
	return;
}

void Word2Bytes( unsigned char *s, unsigned short v )
{
	if( s == NULL )
		return;
#ifndef BIG_ENDIAN_ORDER
	s[1] = (unsigned char)( v >> 8 );		// 高字节放高位	
	s[0] = (unsigned char)( v & 0xff );
#else
	s[0] = (unsigned char)( v >> 8 );		// 低字节放高位	
	s[1] = (unsigned char)( v & 0xff );
#endif
	return;
}

//把byte stream转换成word
void Bytes2Word( unsigned short *v, unsigned char *s )
{
	if( v == NULL || s == NULL )
		return;
#ifndef BIG_ENDIAN_ORDER
	*v = (unsigned short)s[1];		// 高字节放高位	
	*v = ( (*v) << 8 ) | (unsigned short)s[0];		
#else
	*v = (unsigned short)s[0];		// 低字节放高位	
	*v = ( (*v) << 8 ) | (unsigned short)s[1];		
#endif
	return;
}

//把dword转换成byte stream
void DWord2Bytes( unsigned char *s, unsigned long v )
{
	if( s == NULL )
		return;
#ifndef BIG_ENDIAN_ORDER
	s[3] = (unsigned char)( v >> 24 );		// 高字节放高位	
	s[2] = (unsigned char)( ( v >> 16 )& 0xff );
	s[1] = (unsigned char)( ( v >> 8 )& 0xff );
	s[0] = (unsigned char)( v & 0xff );
#else
	s[0] = (unsigned char)( v >> 24 );		// 低字节放高位	
	s[1] = (unsigned char)( ( v >> 16 )& 0xff );
	s[2] = (unsigned char)( ( v >> 8 )& 0xff );
	s[3] = (unsigned char)( v & 0xff );
#endif
	return;
}

//把byte stream转换成dword
void Bytes2DWord( unsigned long *v, unsigned char *s )
{
	if( v == NULL || s == NULL )
		return;
#ifndef BIG_ENDIAN_ORDER
	*v = (unsigned long)s[3];		// 高字节放高位	
	*v = ( (*v) << 8 ) | (unsigned long)s[2];		
	*v = ( (*v) << 8 ) | (unsigned long)s[1];		
	*v = ( (*v) << 8 ) | (unsigned long)s[0];		
#else
	*v = (unsigned long)s[0];		// 低字节放高位	
	*v = ( (*v) << 8 ) | (unsigned long)s[1];		
	*v = ( (*v) << 8 ) | (unsigned long)s[2];		
	*v = ( (*v) << 8 ) | (unsigned long)s[3];		
#endif
	return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -