#define BIG_ENDIAN 0 #define LITTLE_ENDIAN 1 int endian(void);
#include <stdio.h> #include <endian.h> int main() { if ( endian() == LITTLE_ENDIAN) printf("Little endian\n"); else printf("Big endian\n"); }
int endian(void) { int i = 0x00000001; if ( ((char *)&i)[0] ) return LITTLE_ENDIAN; else return BIG_ENDIAN; }
int endian(void) { int i = 0x00000001; return ((char *)&i); }
uint32 get_data(void *mem, byte size) { uint32 data = 0; byte i; if(size <= 4) { for(i = 0; i < size; i++) { data = ((uint32)data << 8) | ((byte *)mem)[i]; } } return(data); }
uint32 htonl(uint x) { int i=0x00000001; char ar[4]; if ( ((char *)&i)[0] ) { byte a[4]; byte b[4]; *((uint32 *)a) = x; b[0] = a[3]; b[1] = a[2]; b[2] = a[1]; b[3] = a[0]; return *((uint32 *)b); } else { return x; } }
uint32 htonl(uint x) { char ar[4]; ar[0] = (x & 0xff000000) >> 24; ar[1] = (x & 0x00ff0000) >> 16; ar[2] = (x & 0x0000ff00) >> 8; ar[3] = (x & 0x000000ff) >> 0; return *(uint32 *)ar; }
uint32 htonl(uint x) { char ar[4]; for(i=0; i<4; i++) { ar[i] = (x & (0xff << ((3-i)*8))) >> 8*(3-i); } return *(uint32 *)ar; }
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
설명
사용방법
코드
또 다른 코드
변경사항
Recent Posts
Archive Posts
Tags