2012年1月10日 星期二

Big And Little Endian

http://www.linuxhowtos.org/data/6/byteorder.html

Big endian and Little endian computers

Virtually all computer architectures are byte addressable. If an int is four bytes, there are two different ways to store this. Suppose the address of the int is A. In a so-called big endian computer, the highest order byte is stored at A, and the lowest order byte is stored at address A+3. In a so-called little endian computer, address A stores the least significant byte and the most significant byte is at address A+3.

Big endian computer architectures include the IBM 370, the Motorola 68000 and Sun Sparc. Little endian computers include the intel series (80486, pentium etc) and VAX.

Consider the decimal integer 91,329. This is 00 01 64 C1 in hexidecimal. If this were to be stored at address A in a big endian computer, 00 would be at address A, 01 at address A+1 64 at address A+2, and C1 at address A+3. On a little endian computer, C1 would be the value at address A, 64 at address A+1, 01 at address A+2, and 00 at address A+3.

Computer networks are big endian. This means that when little endian computers are going to pass integers over the network (IP addresses for example), they need to convert them to network byte order. Likewise, when the receive integer values over the network, they need to convert them back to their own native representation.

There are four functions that do this.

unsigned long htonl(unsigned long)
host to network conversion for long ints (4 bytes)
unsigned short htons(unsigned short)
host to network conversion for short ints (2 bytes)
unsigned long ntohl(unsigned long)
network to host conversion for long ints
unsigned short ntohs(short)
network to host conversion for short ints

On big endian computers these functions simply return their arguments.

The terms big endian and little endian are borrowed from Gulliver's Travels.

Socket Coding Function

inet_ntoa(), inet_aton(), inet_addr

Convert IP addresses from a dots-and-number string to a struct in_addr and back

Prototypes

#include  #include  #include   // ALL THESE ARE DEPRECATED!  Use inet_pton()  or inet_ntop() instead!!  char *inet_ntoa(struct in_addr in); int inet_aton(const char *cp, struct in_addr *inp); in_addr_t inet_addr(const char *cp);


Reference:
http://www.retran.com/beej/inet_ntoaman.html

2012年1月9日 星期一

Header File and Include

Method 1: (Not very rigid)
1. Sometimes you wll write a sub module in the other file
2. then you didn't link it.
3. and can call it.



Method 2: (Serious)
1. you should Define function name before each function usage
2. you should add the header file.



{{{
Time_C.cpp

#include "vxWorks.h"
#include "timexLib.h"
#include "stdio.h"


#define ITERATIONS 200

/*Function Define Region */
int printit(void);
void timing(void);


void timing(void) {
printit();
}

int printit(void) {
int i;
for (i=0; i < ITERATIONS; i++) {
printf("Hello, I am i %d\n", i);
}
}

////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
Add the 'include ' Time_C content, then use the timeing
////////////////////////////////////////////////////////////
/* Define user function */
#include "Time_C.cpp"

void usrAppInit (void) {
#ifdef USER_APPL_INIT
USER_APPL_INIT; /* for backwards compatibility */
#endif

/* add application specific code here */
timing();
}





}}}

2011年12月28日 星期三

Useful Alias

alias 454FLX='ssh adminrig@172.16.7.253'
alias dumd='du -h --max-depth=1 | sort -k2'

2011年12月21日 星期三

Java parameter

-xmx maxmimum heap size
-xms minimum heap size


From 2011_12_22 core-meeting report

2011年11月27日 星期日

Sort

Multiple Sort usethe

sort -k filed1,field1 -k filed2.field2(g)

becareful,
sort -k 14,14 -k 16,16g R_CPU1_Q_CPU8.blat | less

兩個相同, 代表只用相同 key, 而不是 key 後的content

link

ln -s


-s soft_link, when there are cross-device