Results 1 to 4 of 4
- 07-24-2009, 10:25 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 4
- Rep Power
- 0
- 07-24-2009, 09:13 PM #2
Member
- Join Date
- Jul 2009
- Posts
- 4
- Rep Power
- 0
Simpler way to do the same
import java.util.Scanner;
public class toBinary {
/**
* @author : javamadd
*/
public static void main(String[] args) {
int num;
System.out.println("enter the decimal number");
Scanner scanboy = new Scanner(System.in);
num = scanboy.nextInt();
System.out.print("The decimal number is " + num);
String binary = Integer.toBinaryString(num);
System.out.print(" And the corresponding Binary is ");
System.out.print( ""+ binary);
}
}
- 07-25-2009, 03:28 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
@OP, what you mean by recursive method? Can you explain bit more clearly. What javamadd explain is straightforward, no any recursive process going on.
- 07-25-2009, 01:44 PM #4
Member
- Join Date
- Jul 2009
- Posts
- 6
- Rep Power
- 0
Reccursion method to convert decimal to binary.
hey here is the code :
class Binary
{
int a1,b1;
void convert(int a1)
{
b1 = a1 % 2;
if(a1 > 0)
{
convert(a1/2);
System.out.println("binary bits are = "+b1); //i think the result would you get reverse of the byte so u take care about it
}
}
}
class DECTOBIN
{
public static void main(String args[])
{
Binary obj = new Binary();
obj.a1 = Integer.parseInt(args[0]);
obj.convert(obj.a1);
}
}
Ok well. this is the code. But i didnt try it.
Similar Threads
-
how to convert decimal value into 8-bit binary value
By tOpach in forum New To JavaReplies: 4Last Post: 10-26-2009, 10:17 PM -
Eclipse- Decimal to binary
By queen_vee in forum New To JavaReplies: 1Last Post: 02-24-2009, 02:17 PM -
Convert decimal to binary..pls help..newbie here
By mephisto772 in forum New To JavaReplies: 5Last Post: 02-12-2009, 08:17 AM -
Use recursion to convert binary to...
By coco in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 07:46 AM -
Converts a binary number to a decimal
By cachi in forum New To JavaReplies: 1Last Post: 08-01-2007, 09:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks