- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to convert from decimal to binary
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
- Related Articles
- Java program to convert decimal number to binary value
- Java program to convert binary number to decimal value
- Java Program to convert binary number to decimal number
- Convert Decimal to Binary in Java
- Java Program to convert from decimal to hexadecimal
- C# Program to Convert Binary to Decimal
- Haskell Program to convert Decimal to Binary
- Haskell Program to convert Binary to Decimal
- Swift Program to convert Decimal to Binary
- Swift Program to convert Binary to Decimal
- C# Program to Convert Decimal to Binary\n
- C++ Program To Convert Decimal Number to Binary
- Python program to convert decimal to binary number
- Convert decimal to binary number in Python program
- C program to convert decimal fraction to binary fraction

Advertisements