Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Nigel Wade Newsgroups: comp.lang.java.programmer Subject: Re: boolean to int : was char to decimal Date: Fri, 06 May 2011 15:35:34 +0100 Lines: 36 Message-ID: <92if9mFoa4U1@mid.individual.net> References: <92ea64F3avU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: individual.net tvAVcIVmIugs0hp7YXB4twNLtOoNsXjUMxnP51yPdWADA4XdjC Cancel-Lock: sha1:p36C9Mm4fn0em3aIGPK24JkQ2qg= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.1.16) Gecko/20101125 SUSE/3.0.11 Thunderbird/3.0.11 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3688 On 06/05/11 14:00, Jeff Higgins wrote: > On 05/05/2011 04:03 AM, Lawrence D'Oliveiro wrote: >> In message, Ian Shef >> wrote: >> >> Funny, they could do all this for char, but not for boolean. > > Recently I was translating a piece of C++ code to Java. > I'm wondering how others might make this translation. > Thanks, JSH. > > double d2; > double d3; > double e; > > C++ test: > int test = (int(d2 > e) << 1) + int(d3 > e); > > Java test: > int t = d2 > e ? 1<<1 : 0; > int test = d3 > e ? t+1 : t; > If you intend to keep the obfuscation to a maximum, with shorthand one-liners, then: int test = ((d2>e)?2:0) | ((d3>e)?1:0); Of course, the idiosyncrasies of C/C++ do permit a higher degree of obfuscation for the intent of the code. -- Nigel Wade