1,105,416 Community Members

Binary-to-decimal

Member Avatar
cherry.basilio2
Newbie Poster
1 post since Mar 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

How do you convert a decimal to binary and vice versa? using netbeans ide

Member Avatar
<M/>
Industrious Poster
4,473 posts since Apr 2012
Reputation Points: 106 [?]
Q&As Helped to Solve: 139 [?]
Skill Endorsements: 114 [?]
Featured
 
0
 
Member Avatar
mvmalderen
Nearly a Posting Maven
2,370 posts since Feb 2009
Reputation Points: 2,071 [?]
Q&As Helped to Solve: 282 [?]
Skill Endorsements: 40 [?]
 
1
 

Integer.toBinaryString(int) in case you don't have to implement the algorithm yourself.

Also note that if you write e.g. int x = 5; the 5 is actually stored in binary.
System.out.println(x); prints 5 because the binary value in x is converted to base 10 for display.

Member Avatar
JamesCherrill
... trying to help
10,387 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,752 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
1
 

this may help
http://www.roseindia.net/java/java-conversion/BinaryToDecima.shtml

... or not. That's a really tortuous and horrible way to see if a string just contains '0' and '1' (if you can work it out at all, given the lousy coding standards). There may be some good stuff on RoseIndia, but most of it,, like this one, seems to be rubbish. I certainly would not use it as a reference source.

Member Avatar
jwenting
duckman
8,364 posts since Nov 2004
Reputation Points: 1,399 [?]
Q&As Helped to Solve: 447 [?]
Skill Endorsements: 35 [?]
Infraction Points: 5
Team Colleague
 
0
 

don't like to roseindia, it's the worst excuse for a programming help website out there.
Or if you link to them, link to them as an example how not to do something.

mvmalderen has the correct answer, unless of course you are receiving a different binary representation from the one that Java is expecting (little endian vs. big endian, etc.).

Member Avatar
stultuske
Posting Expert
5,333 posts since Jan 2007
Reputation Points: 938 [?]
Q&As Helped to Solve: 776 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 

another side-point: the IDE you use is not relevant.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: