DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Converting boolean to integer (http://www.daniweb.com/forums/thread109038.html)

orcboyx Feb 13th, 2008 6:41 pm
Converting boolean to integer
 
Is there an easy way to convert a simple integer into a boolean type?

Acidburn Feb 13th, 2008 6:46 pm
Re: Converting boolean to integer
 
Does this help?
http://forum.java.sun.com/thread.jsp...sageID=1092147

Ezzaral Feb 13th, 2008 7:06 pm
Re: Converting boolean to integer
 
(i != 0)

DangerDev Feb 14th, 2008 3:04 am
Re: Converting boolean to integer
 
use:
boolean b;
int iSomeValue;

b=true;
if(iSomeValue==0)b=false;
or use function
boolean intToBool(int iVal)
{
 boolean b=true;
 if(iVal==0)b=false;
 return b;
}

Ezzaral Feb 14th, 2008 1:04 pm
Re: Converting boolean to integer
 
That is a lot more code than is needed. The conversion only needs the evaluation of intVal!=0, so the function reduces to
boolean intToBool(int value){
  return (value != 0);
}

orcboyx Feb 16th, 2008 7:10 pm
Re: Converting boolean to integer
 
Thanks for the help, by th way i used ezzral's method it was quick and simple, i also found out i could've just started with a boolean by setting random generator class to boolean type.


All times are GMT -4. The time now is 3:04 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC