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

Recommended Answers

All 5 Replies

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.

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.

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.).

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.