Newsgroups: comp.ai.genetic
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!godot.cc.duq.edu!newsgate.duke.edu!news.mathworks.com!news.kei.com!newsfeed.internetmci.com!swrinde!sdd.hp.com!col.hp.com!news.dtc.hp.com!hplntx!hplb!jco
From: jco@hplb.hpl.hp.com (Joao Oliveira)
Subject: Re: What is the algorithm for Decimal to Binary Conversion?
Sender: news@hplb.hpl.hp.com (Usenet News Administrator)
Message-ID: <DrrpI4.DsM@hplb.hpl.hp.com>
Date: Tue, 21 May 1996 18:18:03 GMT
References: <babbitt-0505960832200001@dal10-22.ppp.iadfw.net> <31A0FCEE.5C4B@cs.msu.su>
Nntp-Posting-Host: incl05.hpl.hp.com
Organization: Hewlett-Packard Laboratories, Bristol, England
X-Newsreader: TIN [version 1.2 PL0.7]
Lines: 28

Lavrenko V.S. (lavrenko@cs.msu.su) wrote:
: Nichael Cramer wrote:
: > 
: > "Lavrenko V.S." <lavrenko@cs.msu.su> writes:
: >    To print `12345` in binary (reverse order), C++:
: >    main(){for(int x=12345;x;x/=2)printf("%c","01"[x%2]);}
: >    Who can shorter?
: > (format nil "~2R" 12345)

: Sorry, I've done a mistake in previous mail.
: Instead of PRINT HEX$(12345) the answer is PRINT BIN$(12345).
: I didn't program in Basic many years.
: -- 
: Lavrenko Victor

main(){for(int x=12345;x;x/=2)cout<<"01"[x%2];} 
main(){for(int x=24690;x/=2;)cout<<"01"[x%2];}
  
These are the smaller I can think of. I didn't include the #include <stream.h>
because you didn't include the <stdlib.h> one? The trick with the "01" was
pretty nifty.
  
joao
--
+ Joao Barreto Fernandes - Intelligent Networked Computing Lab  R&D placement +
+ Hewlett Packard Labs, Filton Rd, Bristol BS12 6QZ England   +44 117 9228714 +
+ jco@hplb.hpl.hp.com   http://www-incl/~jco  http://www.di.fc.ul.pt/~barreto +
+       'All points of view are my own and not necessarily HP's as well'      +
