Byte order (or you are both wrong)

Lawrence Crowl crowl at rochester.ARPA
Sun Apr 13 07:06:42 AEST 1986


Neither big-endian nor little-endian numbers can be sorted lexicographically.
Since the only reason for for attempting to mix character string and number
data is to save time, we must assume that we will have an arbitrary mix if
characters and numbers, including different size numbers.

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.

In both cases, using two's complement sign representation causes problems.
For example, both have -41 > 41.  CLEARLY WRONG.

The basic problem is that our definition of lexicographic sorting is
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.
Note that many part numbering schemes have intermixed letters and digits.
-- 

Lawrence Crowl             716-275-5766        University of Rochester
                                               Computer Science Department
...!{allegra,decvax,seismo}!rochester!crowl    Rochester, New York,  14627



More information about the Comp.lang.c mailing list