|
-
June 19th, 2010, 05:04 PM
#1
endian and proxy representation
Given:
A [0..4] - where 0..4 represents a bit proxy 4 wide
B [5..8] - where 5..8 represents a bit proxy 4 wide
C [9..12] - where 9..12 represents a bit proxy 4 wide
D [13..16] - where 13..16 represents a bit proxy 4 wide
Lets assume MSB is defined as bit 0 on a Server implemention. Server transmits: 0xABCD
Client is little endian and receives. 0xCDAB. To account for endianness Client converts data to: 0xABCD. If the Client wanted to check a proxy (say 0..4 for the value 'A') the client must subtract 16. True/False? My counterpart made a comment about Server data being backwards and I'm not following his logic. In my view this is mandatory when you're dealing with endianess and nibbles.
Last edited by mop65715; June 20th, 2010 at 01:32 PM.
-
June 20th, 2010, 04:48 PM
#2
Re: endian and proxy representation
First, network communication is big endian. You can of course still use little endian if you write the software for both sides but best practice is to just take big endian as a rule.
Manipulation or intepretation of received data should always be done on data arranged in host byte order. Doing so make it both easier to reuse code and to understand it since all network participants think of the data in the same way.
When checking the proxy values you would do something like
Code:
int proxyA = (data>>12) & 0xF;
proxyB = (data>>8) & 0xF;
proxyC = (data>>4) & 0xF;
proxyD = (data>>0) & 0xF;
regardless of platform (since proxy data is a 16 bit integer).
To convert from network endian to host endian use the functions ntohl, ntohs functions and htonl, htons for the other way.
Your bit numbering is not correct by the way. Bit 0 to bit 4 would span 5 bits, not 4. Also, the most common way of numbering bits is that bit 0 is the LSB i.e. the bit with the value 20
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|