CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2008
    Posts
    1

    [Help me Plz] Decimal to Binary

    //My Problem on this is i need the output to be reversed
    //Example Run:

    //Enter a decimal number
    //100
    //The Decimal Number is: 100
    //Its Binary Representation is:
    //0010011

    //I need the output to be reversed to 1100100
    //Without using the .reverse or .IntegerToBinary methods
    //Any help would be appreciated

    import java.lang.*;
    import java.util.*;
    public class BinaryDecimal
    {
    public static void main(String[ ] args)
    {
    Scanner keyBoard = new Scanner(System.in);
    System.out.println("Enter a decimal number");
    int num = keyBoard.nextInt();
    System.out.println("The Decimal Number is: " + num);
    System.out.println("Its Binary Representation is:");

    while(num != 0)
    {
    int numHold = num / 2;
    if (num % 2 == 0)
    {
    System.out.printf("0");
    }
    else
    {
    System.out.printf("1");
    }
    num = numHold;
    }
    }
    }
    Last edited by Sylvanuz; November 30th, 2008 at 04:14 PM. Reason: Solved Stars

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: [Help me Plz] Decimal to Binary and "Printing Stars"

    We're not going to write it for you, so what, exactly, is the difficulty you have with writing this code?

    The biggest difference between time and space is that you can't reuse time...
    M. Furst
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

    Re: [Help me Plz] Decimal to Binary and "Printing Stars"

    See if you can find an apropriate method in the Integer class.

    Laitinen

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured