- initial import
git-svn-id: http://moon:8086/svn/mips@1 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef UINT8
|
||||
#define UINT8 unsigned char
|
||||
#endif
|
||||
#ifndef UINT16
|
||||
#define UINT16 unsigned short
|
||||
#endif
|
||||
#ifndef UINT32
|
||||
#define UINT32 unsigned long
|
||||
#endif
|
||||
|
||||
UINT8 g_pattern8[] = {0x01, 0x02, 0x03, 0x4, 0x05, 0x06, 0x07, 0x08};
|
||||
UINT16 g_pattern16[sizeof(g_pattern8)/2] = {0};
|
||||
UINT32 g_pattern32[sizeof(g_pattern8)/4] = {0};
|
||||
UINT8 _g_bytes[4] = {0x12, 0x34, 0x56, 0x78};
|
||||
UINT8 _g_bytes2[4] = {0};
|
||||
|
||||
void MakePattern(void)
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
UINT16 *pPat16 = (UINT16*)g_pattern8;
|
||||
UINT32 *pPat32 = (UINT32*)g_pattern8;
|
||||
|
||||
|
||||
for (i=0; i < sizeof(g_pattern16)/2; i++)
|
||||
{
|
||||
g_pattern16[i] = pPat16[i];
|
||||
}
|
||||
|
||||
for (i=0; i < sizeof(g_pattern32)/4; i++)
|
||||
{
|
||||
g_pattern32[i] = pPat32[i];
|
||||
}
|
||||
}
|
||||
|
||||
void PrintPattern(void)
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
printf("Pattern 8bit:\n");
|
||||
for (i=0; i < sizeof(g_pattern8); i++)
|
||||
{
|
||||
printf("%02X ", g_pattern8[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("Pattern 16bit:\n");
|
||||
for (i=0; i < sizeof(g_pattern16)/2; i++)
|
||||
{
|
||||
printf("%04X ", g_pattern16[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("Pattern 32bit:\n");
|
||||
for (i=0; i < sizeof(g_pattern32)/4; i++)
|
||||
{
|
||||
printf("%08X ", g_pattern32[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int IsEndianBig(void)
|
||||
{
|
||||
int i, result;
|
||||
|
||||
UINT8 *pBuf8;
|
||||
UINT16 *pBuf16;
|
||||
UINT32 *pBuf32;
|
||||
UINT16 halve;
|
||||
UINT32 word;
|
||||
|
||||
|
||||
halve = 0x1234;
|
||||
word = 0x12345678;
|
||||
|
||||
result = -1;
|
||||
|
||||
for (i=0; i < 4; i++)
|
||||
_g_bytes2[i] = _g_bytes[i];
|
||||
|
||||
pBuf8 = (UINT8*)&word;
|
||||
if (((*pBuf8+0) == 0x12) && (*(pBuf8+1) == 0x34) && (*(pBuf8+2) == 0x56) && (*(pBuf8+3) == 0x78))
|
||||
{
|
||||
pBuf8 = (UINT8*)&halve;
|
||||
if (((*pBuf8+0) == 0x12) && (*(pBuf8+1) == 0x34))
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
|
||||
pBuf8 = (UINT8*)&word;
|
||||
if (((*pBuf8+0) == 0x78) && (*(pBuf8+1) == 0x56) && (*(pBuf8+2) == 0x34) && (*(pBuf8+3) == 0x12))
|
||||
{
|
||||
pBuf8 = (UINT8*)&halve;
|
||||
if (((*pBuf8+0) == 0x34) && (*(pBuf8+1) == 0x12))
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int eb;
|
||||
|
||||
setbuf(stdout, NULL);
|
||||
|
||||
if (IsEndianBig() == 1)
|
||||
printf("Endian is big\n");
|
||||
if (IsEndianBig() == 0)
|
||||
printf("Endian is little\n");
|
||||
|
||||
MakePattern();
|
||||
PrintPattern();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user