Thread: Hint On C

  1. #1
    Registered User kaushal1111's Avatar
    Join Date
    Jan 2012
    Location
    INDIA
    Posts
    4

    Hint On C

    Hi,
    i want to make a programme that convert any number system to any number system....means binary to hexa decimal....and many more can you give me some hint about this programme.....i think it is made by switch case....?????????

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Firstly, I want you to read this page.

    Now that that's clarified, you need to decide how will you represent numbers with base higher that 16.
    Secondly, "any number system to any number system" is pretty vague. Most ( if not all ) computers store numbers in binary. So you'll want to convert "any number system to binary" and "binary to any number system".

    Hint: A lookup table is the fastest/easiest way to to it. For example:
    Code:
    void printBinary(unsigned int num)
    {
        char digits[2] = { '0', '1' };
        char temp[65] = "";
        char number[65] = "";
    
        do
        {
            temp[0] = digits[num % 2];
            temp[1] = '\0';
            strcat(temp, number);
            strcpy(number, temp);
    
            num /= 2;
        }while (num != 0);
    
        printf("%s", number);
    }
    Be warned, this code is untested.
    Last edited by GReaper; 01-13-2012 at 10:06 AM.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I want a hint
    By Dan. in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2011, 03:36 PM
  2. I need a hint.
    By hyrule in forum C++ Programming
    Replies: 4
    Last Post: 09-04-2005, 09:31 PM
  3. hi! could anybody help me, a hint at the least
    By alvarorahul in forum C Programming
    Replies: 1
    Last Post: 07-07-2004, 02:37 AM
  4. Just a HINT
    By Diceman in forum C++ Programming
    Replies: 1
    Last Post: 07-25-2003, 05:27 PM
  5. i need hint...
    By jk81 in forum C Programming
    Replies: 3
    Last Post: 09-12-2002, 08:38 PM