Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!emory!cambridge.apple.com!bloom-beacon!eru!luth!sunic!mcsun!ukc!acorn!ixi!clive From: clive@ixi.co.uk (Clive Feather) Newsgroups: comp.lang.c Subject: Re: binary constants Message-ID: Date: 22 Nov 89 07:29:52 GMT References: <305@frf.omron.co.jp> <20830@mimsy.umd.edu> Reply-To: clive@ixi.co.uk (Clive D.W. Feather) Organization: IXI Limited, Cambridge, UK Lines: 43 [I finally get to follow up to Chris Torek] In article <20830@mimsy.umd.edu> chris@mimsy.umd.edu (Chris Torek) writes: >One of my favourite silly ideas for C is now ruled out by X3J11's >`#' `stringize' preprocessing operator (or at least, would require >some other syntax), but it went like this: Instead of having hex, >decimal, octal, binary, etc., constant syntaxes, why not have a >single syntax for `based numbers'? The initial radix would always >be decimal; the format would be something like > #(base,expr) >Numbers in the `expr' part would be interpreted in the base given by >the `base' expression. Any value from 2 to 36 would be legal for the >base. All `numbers' would be of the form > [0-9][0-9a-zA-Z]* >where ordinary digits represent themselves and letters represent digits >>= 10 in the obvious manner. (Whether digits greater than the base >would be legal is essentially irrelevant.) Algol 68 (yes, some of us once used it) uses the following notation for bit patterns: 2r11001000 == 200 4r3020 == 200 8r310 == 200 16rc8 == 200 This could be trivially extended to any base up to 36. It has advantages over Chris's notation, in that the numbers are already pp-numbers (see the discussion in comp.std.c), and it doesn't use a new operator. >The sneaky (or silly) bit is that both `base' and `expr' would be >arbitrary constant expressions. This would be useful for obfuscation >such as > #(3+#(2,#(6,13)-0010),#(5,11)/30) >which is actually 1. >(I think.) You're right - silly is the word :-). -- Clive D.W. Feather IXI Limited clive@ixi.uucp ...!uunet!ukc!ixi!clive (riskier)