CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2005
    Posts
    382

    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.

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    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
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured