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

Threaded View

  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

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