Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!cmcl2!philabs!pwa-b!mmintl!franka From: franka@mmintl.UUCP (Frank Adams) Newsgroups: net.lang.c Subject: Re: Byte order Message-ID: <1298@mmintl.UUCP> Date: Mon, 21-Apr-86 19:38:15 EST Article-I.D.: mmintl.1298 Posted: Mon Apr 21 19:38:15 1986 Date-Received: Thu, 24-Apr-86 07:10:07 EST References: <17162@rochester.ARPA> <139200027@uiucdcsb> <17312@rochester.ARPA> Reply-To: franka@mmintl.UUCP (Frank Adams) Organization: Multimate International, E. Hartford, CT Lines: 45 In article <17312@rochester.ARPA> crowl@rochester.UUCP (Lawrence Crowl) writes: >>I wrote: >>>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 >>>require strings to be padded with nulls, or numbers to be padded with zeros. > >Arch D. Robison wrote: >>... -4 = AAAAZ -3 = AAAZ -2 = AAZ -1 = AZ >> 0 = M 1 = Z 2 = ZZ 3 = ZZZ 4 = ZZZZ ... >> > >An interesting solution. I totally failed to consider unary notations. Just >to keep the answers honest, I will add the requirement that some efficient >form of representation be used. Radix notation is efficient, but you are not >required to use it. For extra credit, extend your notation to deal with >non-integral values. This is easy under current notation if the integral >part is the same. Basically, you use a unary notation (pure or modified) to indicate how long the number is, and the number follows. Using the scheme above, 257 would be ZZZ257. One and a half would be Z15. This is essentially floating point notation. This has to be modified a bit to deal with negative numbers. One possibility is to allocate separate "exponent" spaces for positive and negative numbers. E.g., for positive numbers, the exponents are: ... -4 = NNNNT -3 = NNNT -2 = NNT -1 = NT 0 = T 1 = ZT 2 = ZZT 3 = ZZZT 4 = ZZZZT For negative numbers, the exponents are: ... -4 = MMMMG -3 = MMMG -2 = MMG -1 = MG 0 = G 1 = AG 2 = AAG 3 = AAAG 4 = AAAAG Also, for negative numbers, the digits should be in (9's) complement form. Thus -1 would be AG8. A special notation, e.g. NA, is required for zero. This can of course be done somewhat better. A higher radix can be used, and the exponent encoding can be further optimized. But the point is to describe the approach, not to work out all the details. Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Multimate International 52 Oakland Ave North E. Hartford, CT 06108