Converting boolean to integer

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2007
Posts: 18
Reputation: orcboyx is an unknown quantity at this point 
Solved Threads: 0
orcboyx orcboyx is offline Offline
Newbie Poster

Converting boolean to integer

 
0
  #1
Feb 13th, 2008
Is there an easy way to convert a simple integer into a boolean type?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: Converting boolean to integer

 
0
  #2
Feb 13th, 2008
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,505
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Converting boolean to integer

 
0
  #3
Feb 13th, 2008
(i != 0)
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 483
Reputation: DangerDev has a spectacular aura about DangerDev has a spectacular aura about 
Solved Threads: 59
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Pro in Training

Re: Converting boolean to integer

 
0
  #4
Feb 14th, 2008
use:
  1. boolean b;
  2. int iSomeValue;
  3.  
  4. b=true;
  5. if(iSomeValue==0)b=false;
or use function
  1. boolean intToBool(int iVal)
  2. {
  3. boolean b=true;
  4. if(iVal==0)b=false;
  5. return b;
  6. }
Last edited by DangerDev; Feb 14th, 2008 at 3:07 am. Reason: uncomlete
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,505
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Converting boolean to integer

 
0
  #5
Feb 14th, 2008
That is a lot more code than is needed. The conversion only needs the evaluation of intVal!=0, so the function reduces to
  1. boolean intToBool(int value){
  2. return (value != 0);
  3. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 18
Reputation: orcboyx is an unknown quantity at this point 
Solved Threads: 0
orcboyx orcboyx is offline Offline
Newbie Poster

Re: Converting boolean to integer

 
0
  #6
Feb 16th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC