Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang.c Subject: Re: Byte order (or you are both wrong) Message-ID: <2568@utcsri.UUCP> Date: Wed, 16-Apr-86 15:34:53 EST Article-I.D.: utcsri.2568 Posted: Wed Apr 16 15:34:53 1986 Date-Received: Wed, 16-Apr-86 15:43:05 EST References: <7046@cca.UUCP> <6578@utzoo.UUCP> <17162@rochester.ARPA> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 46 Summary: In article <17162@rochester.ARPA> crowl@rochester.UUCP (Lawrence Crowl) writes: > >When sorted lexicographically, the numbers in little-endian format are >sorted based on the low order digit. For example 32 > 41. CLEARLY WRONG. > >When sorted lexicographically, the numbers in big-endian format are sorted >based on the first high order digit of each number. This presents a problem >when numbers are of different sizes. For example, 32 > 126. CLEARLY WRONG. >incompatible with our (natural) definition of numeric sorting. > >CHALLENGE: Come up with a scheme for representing numbers, and a sorting >scheme in which numbers sort naturally. Your scheme must deal with variable >length character strings and variable size numbers. That is, you cannot >requires strings to be padded with nulls, or numbers to be padded with zeros. How about prepending the digit count to big-endian digit strings? so 32 and 126 become 232 and 3126, and a lexical comparison gives 3126 > 232. Of course, leading zeroes in the significand cannot be used. If the strings are of different lengths ( and both positive ) then the longer one is always greater. To support negative numbers, the length digit could be biased. The following convention supports signed strings of length 1-5: 1 2 3 4 5 < length of number 5 6 7 8 9 < prefix for +ve numbers 4 3 2 1 0 < prefix for -ve numbers The significand digits in a negative number would have to be 9's complemented, so 32, 126,-37 and -8 are 632, 7126, 362 and 41. There are two 0's, 49 and 50. ( This makes zero an exception to the leading-zero rule ). Note also that -99 becomes 300,and that 2999 is illegal. This is starting to resemble a floating-point scheme... To allow longer strings, just allow a bigger 'length' field - more digits, or a whole byte. >Note that many part numbering schemes have intermixed letters and digits. But what significance do letters have? do you want them to be ignored, or to be assigned a dictionary order with the numbers? P.S. this rather obscure scenario hardly seems reason to state that little- and big-endians are both wrong. -- "If you aren't making any mistakes, you aren't doing anything". ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg