Results 1 to 5 of 5
  1. #1
    DMarsh12 is offline Member
    Join Date
    Mar 2011
    Posts
    43
    Rep Power
    0

    Default Decimal to Binary

    I need to develop a code that will convert decimal to binary....I have gotten stuck though on this certain part and was wonder
    ing if any of you would be able to help see where my error is...

    Java Code:
    public class binaryconvert {
    	
    public static void main(String [] args)
    {	
    	int convert (int j)
    	{
    		int n=j;
    		if (n==0) return 1;
    		else{
    			convert(n/2);
    			System.out.println(n%2);
    		}
    		
    	}
    }
    }
    any help would be greatly appreciated !

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default Re: Decimal to Binary

    Do you have to write your own implementation, or can you use the Integer.toBinaryString() method?

    You need to be returning something if n != 0.

  3. #3
    DMarsh12 is offline Member
    Join Date
    Mar 2011
    Posts
    43
    Rep Power
    0

    Default Re: Decimal to Binary

    Quote Originally Posted by Iron Lion View Post
    Do you have to write your own implementation, or can you use the Integer.toBinaryString() method?

    You need to be returning something if n != 0.
    we need to write our own implementation we cannot use that method...maybe that's where my program is having an error but i don't understand what it's supposed to be

  4. #4
    javin.paul is offline Member
    Join Date
    Oct 2011
    Posts
    35
    Rep Power
    0

    Default Re: Decimal to Binary

    do you want to write function which prints binary version in String format or it should return binary value ?

  5. #5
    DMarsh12 is offline Member
    Join Date
    Mar 2011
    Posts
    43
    Rep Power
    0

    Default Re: Decimal to Binary

    Quote Originally Posted by javin.paul View Post
    do you want to write function which prints binary version in String format or it should return binary value ?
    it should return the binary value not the string format

Similar Threads

  1. Replies: 5
    Last Post: 08-25-2011, 07:32 PM
  2. Decimal to binary, octal to decimal
    By matejm1994 in forum New To Java
    Replies: 3
    Last Post: 12-26-2010, 09:59 AM
  3. Binary to Decimal Converter
    By c_walker in forum New To Java
    Replies: 15
    Last Post: 11-24-2009, 02:38 PM
  4. Convert binary into decimal
    By WarmRegards in forum New To Java
    Replies: 8
    Last Post: 10-18-2009, 02:32 PM
  5. Eclipse- Decimal to binary
    By queen_vee in forum New To Java
    Replies: 1
    Last Post: 02-24-2009, 02:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •