Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!cca!g-rh From: g-rh@cca.UUCP (Richard Harter) Newsgroups: net.lang.c Subject: Re: Byte order (or you are both wrong) Message-ID: <7485@cca.UUCP> Date: Thu, 24-Apr-86 00:34:15 EST Article-I.D.: cca.7485 Posted: Thu Apr 24 00:34:15 1986 Date-Received: Sat, 26-Apr-86 05:54:57 EST References: <7046@cca.UUCP> <6578@utzoo.UUCP> <17162@rochester.ARPA> <2568@utcsri.UUCP> Reply-To: g-rh@cca.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge Lines: 45 Summary: Representation handling chars, ints, etc. >In article <17162@rochester.ARPA> crowl@rochester.UUCP (Lawrence Crowl) writes: > >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. Presented without endorsement: Addressing nomenclature -- big endian (i.e. msb is bit 0, etc.) Item is divided into five parts: Part I - sign bit (0 is negative, 1 is postive) Part II - Size of field size in unary, i.e. string of 1's terminated by 0 Part III - Field size, in binary (Field size is size of field to left of implicit decimal point. Part IV - Portion of string to left of implied decimal point, encoded in bytes. Part V - Portion of string to right of implied decimal point, encoded in ternary, using two bits per ternary digit, as follows: 00 Sentinel, terminating right field 01 ternary 0 02 ternary 1 03 ternary 2 All numbers are represented as ascii characters. The point of the ternary representation (or something equivalent) is that it provides for a sentinel for variable length strings that sorts lexicographically. If an integer is to be considered as a number and compared in that fashion it goes in the left field -- if it is to be considered as a character string it goes in the right field. I believe that this representation meets the challenge. I sincerely hope that I never have to work with it. Richard Harter, SMDS Inc.