Thread: Typing decimal number and cover it binary number!

  1. #31
    Registered User
    Join Date
    Apr 2011
    after problem is solved everything looks easier.

    Fact is none of you genius notice a bracket is missing.
    Instead of that you were giving something that some people call 'advice'.

  2. #32
    Registered User
    Join Date
    Mar 2011
    Can you believe this guy?

    He hand types in a copy of his code, complete poor indentation and with additional typos (which he propagates into subsequent posts), and expected others to find HIS mistake.

    Sounds about 17 to me...

  3. #33
    Join Date
    Aug 2010
    Ontario Canada
    Quote Originally Posted by Kazumi View Post
    I am not that expert. I do not understand your code at all.

    I tried pasting but just syntax error...
    Oh for crying out loud... the syntax error is from my "... get number from keyboard" line. You didn't really expect that to work did you?
    I was showing you the calculation...

    Here is the exact code I used to test it before posting...
    #include <stdio.h>
    int main (void)
        char binary[17] = {0};
        int number;
        printf("Enter a number from 0 to 65535 : ");
        scanf("%d", &number);
        for (int x = 15; x > -1; x--)
          { if (number & 1)
               binary[x] = '1';
               binary[x] = '0';
            number >>= 1; }
        printf("16bit binary :  %s\n\n", binary);
        return 0; }
    ... and you couldn't figure out how to type in two simple lines that you already had in your original code???

    In fact I could have simplified it even further...
        for (int x = 15; x > -1; x--)
          { binary[x] = '0' + (number & 1);
            number >>= 1; }
    now THAT I figured you wouldn't get... hense the more obvious version.
    Last edited by CommonTater; 04-16-2011 at 07:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Number to Decimal
    By theCanuck in forum C++ Programming
    Replies: 12
    Last Post: 02-09-2011, 11:25 PM
  2. Number of digits in a decimal number
    By maverix in forum C Programming
    Replies: 7
    Last Post: 11-04-2007, 12:12 PM
  3. how to remove zero after decimal number
    By abhay_m8 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2007, 02:30 AM
  4. Replies: 9
    Last Post: 10-07-2006, 05:37 AM
  5. How to get the decimal part of a number...
    By Caldus in forum C++ Programming
    Replies: 13
    Last Post: 06-12-2006, 06:41 PM