# Java Program to convert from decimal to binary

Java 8Object Oriented ProgrammingProgramming

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

Live Demo

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
{"ft_lang_label":"__label__en","ft_lang_prob":0.62967986,"math_prob":0.6873982,"size":617,"snap":"2021-31-2021-39","text_gpt3_token_len":135,"char_repetition_ratio":0.14192496,"word_repetition_ratio":0.0,"special_character_ratio":0.24473257,"punctuation_ratio":0.15789473,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9579638,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-20T16:32:18Z\",\"WARC-Record-ID\":\"<urn:uuid:50d03807-8732-4687-ae69-9f46c9868baa>\",\"Content-Length\":\"30682\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b49476fc-dc09-4dd7-8071-189f54a7ee98>\",\"WARC-Concurrent-To\":\"<urn:uuid:bb38263e-505c-48db-ae15-32bd3f011429>\",\"WARC-IP-Address\":\"72.21.91.42\",\"WARC-Target-URI\":\"https://www.tutorialspoint.com/java-program-to-convert-from-decimal-to-binary\",\"WARC-Payload-Digest\":\"sha1:6BTPAOMKGOKD5F6WT2OK33CZVYH6BLF6\",\"WARC-Block-Digest\":\"sha1:ZVK5NHXSV32LD6MFGS3JDXLO54R2PJPC\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780057083.64_warc_CC-MAIN-20210920161518-20210920191518-00150.warc.gz\"}"}