Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!genrad!decvax!ucbvax!sdcsvax!ucsdhub!jack!man!crash!gryphon!greg From: greg@gryphon.CTS.COM (Greg Laskin) Newsgroups: comp.lang.c Subject: Re: Printing binary (was: Re: Why college?) Message-ID: <2034@gryphon.CTS.COM> Date: Mon, 26-Oct-87 03:46:07 EST Article-I.D.: gryphon.2034 Posted: Mon Oct 26 03:46:07 1987 Date-Received: Wed, 28-Oct-87 02:06:01 EST References: <35@ateng.UUCP> <3194@sol.ARPA> <2783@xanth.UUCP> <235@snark.UUCP> <2072@watcgl.waterloo.edu> <1646@spar.SPAR.SLB.COM> Reply-To: greg@gryphon.CTS.COM (Greg Laskin) Organization: Trailing Edge Technology, Redondo Beach, CA Lines: 22 Summary: recursion strikes a nerve In article <1646@spar.SPAR.SLB.COM> hunt@spar.UUCP (Neil Hunt) writes: >This is crying out for recursion: > void > print_binary(value, bits) > int value, bits; > { > if(--bits > 0) > print_binary(value >> 1, bits); > putchar((value & 0x1) + '0'); > } > Why would this cry out to incur the additional overhead of recursion just to flip the order of the bits around when you could easily pick the bits off the left side and use a simple loop to do the job? Pretty algorithm though. -- Greg Laskin "When everybody's talking and nobody's listening, how can we decide?" INTERNET: Greg.Laskin@gryphon.CTS.COM UUCP: {hplabs!hp-sdd, sdcsvax, ihnp4}!crash!gryphon!greg UUCP: {philabs, scgvaxd}!cadovax!gryphon!greg