Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mdcbbs!halloran From: halloran@mdcbbs.com (M. J. Halloran II (McDonnell Douglas M&E)) Newsgroups: comp.lang.c Subject: Define Big/Little Endian ( was: Re: RISC Mach...) Message-ID: <686.25c92d5f@mdcbbs.com> Date: 2 Feb 90 06:49:02 GMT References: <111@melpar.UUCP> <6200024@ux1.cso.uiuc.edu> Organization: McDonnell Douglas M&E, Cypress CA Lines: 37 In article <6200024@ux1.cso.uiuc.edu>, phil@ux1.cso.uiuc.edu writes: > Another problem you can encounter when dealing with data structure formats > imposed by hardware, particularly external hardware, is the byte order. > An example is handling TCP and IP headers. The exact data structure is > defined very specifically, but making code that can deal with it AND be > portable across big and little endian machines requires a lot of care. --- ------ ------ Let's clerify... > Such portable code may not be the most optimal depending on how it is > done. > > --Phil Howard, KA9WGN-- > These define how bytes within words are ordered. Big endian: Big end first (MSB)(LSB). Little endian: Little end first (LSB)(MSB). ie: typedef union { unsigned char bytes[2]; unsigned long word; } INDIANS; main() { INDIAN indian; indian.word = 0x1234; if ( indian.bytes[0] == 0x12) /* is MSB at lower mem? */ puts ( "Big Endian\n"); else puts ( "Little Endian\n"); }