I'm looking for a way to write a recursive method which convert a decimal to value to its binary equivalent. I can write a method which returns the result as a String, but I can't figure out to write a method which makes calculation with integer values and returns integer as well. I'm waiting for your help.

Thanks in advance.

Please explain what you mean by a decimal value and a binary equivalent. Are you talking about Strings?
For example decimal: "10" and binary: "1010"
An int is 4 bytes of bits. You can display the value of an int in many String formats. But an int is an int.

yes. for instance,

binary(13); >> returns 1101 as a result.

What data type is the 1011? It looks like a String: "1101"

011? It looks like a String: "1101"

no, I said "int" at the beginning.

The only way you can see the value of an int is by formatting it as a String.
You can not see the value of an int without formatting it.
You can use an if statement to test its value:

int anInt = 13;
if (anInt == 13) System.out.println("value of anInt is 13");

The 1101 you show has to be a String for you to see it in that format.

What do you mean by you have written a method which returns the result as a string? Can you post that? Maybe we can start from that.

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.