Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!apple!claris!ames!amdcad!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!cs.tcd.ie!csvax1!fmodwyer From: fmodwyer@cs.tcd.ie (Frank O'Dwyer , ext. 1695) Newsgroups: comp.sys.mac.programmer Subject: Re: base 10 --> base 3 ... Message-ID: <10297@cs.tcd.ie> Date: 25 Aug 88 21:16:22 GMT References: <730059@hpcilzb.HP.COM> Organization: Computer Science Department, Trinity College Dublin Lines: 23 In article <730059@hpcilzb.HP.COM>, tedj@hpcilzb.HP.COM (Ted Johnson) writes: > Does anyone know of an algorithm to convert a positive integer N into > its base 3 representation? (e.g., 14 in base 10 is 112 in base 3). The following procedure does this (written in Turbo pascal). procedure Base3to10(DecimalNumber:integer; var Base3String : str255); begin Base3String := ''; if DecimalNumber = 0 then Base3String := '0' else while DecimalNumber <> 0 do begin Base3String := concat(chr((DecimalNumber mod 3) + ord('0')),Base3String); DecimalNumber := DecimalNumber div 3; end; end; To change to another base, replace occurrences of the number 3 with the new base. Hope this helps.