0

Hi,

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.

3
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by scudzilla
0

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.

0

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.

Edited by NormR1

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.