
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert Decimal to Binary in Java
To convert decimal to binary, Java has a method Integer.toBinaryString(). The method returns a string representation of the integer argument as an unsigned integer in base 2.
Let us first declare and initialize an integer variable.
int dec = 25;
Convert it to binary.
String bin = Integer.toBinaryString(dec);
Now display the “bin” string, which consists of the Binary value. Here is the complete example.
Example
public class Demo { public static void main( String args[] ) { int dec = 25; // converting to binary and representing it in a string String bin = Integer.toBinaryString(dec); System.out.println(bin); } }
Output
11001
Advertisements