how to do conversion decimal to hexidecimal

This is a discussion on how to do conversion decimal to hexidecimal within the C Programming forums, part of the General Programming Boards category; cAn any one help me.... i am doing a program to change (1) decimal to binary (2) decimal to octal ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    4

    how to do conversion decimal to hexidecimal

    cAn any one help me.... i am doing a program to change
    (1) decimal to binary
    (2) decimal to octal
    (3) decimal to hexadecimal

    i dun know to do option 3 care to help.....



    THIS is The coDing attached...
    Attached Files Attached Files

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    you dont convert remainders < 10 to chars in DecToHex()
    use
    Code:
            else
            {
                remainderchar=remainder + '0';
            }
    Kurt

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    6
    In addition to the change ZuK suggested you should also change this code:
    Code:
    temp=temp/16;
    remainder=temp%16;
    with the code:
    Code:
    remainder=temp%16;
    temp=temp/16;
    In other words invert the two operations. You first get the current remainder, than update (divide) the number so that in the next cycle you'll get the next remainder.

  4. #4
    Registered User
    Join Date
    Jul 2007
    Posts
    4

    Thanks guys

    Hi guys.. it dun work again... can someone edit and attach it again.. with comments where the code was changed....

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    No one is here to do the work for you, learn how hex and dec work (and how to inter convert between the two) before going any further.

  6. #6
    Registered User
    Join Date
    Jul 2007
    Posts
    4

    Got it working...

    hi there i got it working.. bb\ut when i retry the option again.. the output does show the same value as my first attempt....
    Attached Files Attached Files

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    If it's a C program, why the cpp extension? Some compilers might attempt to compile your code as C++ based upon the extension, which can cause some problems for you.

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Guessing is no way to learn C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-04-2008, 12:39 PM
  2. Conversion of hexidecimal to decimal
    By twocool82 in forum C Programming
    Replies: 6
    Last Post: 07-09-2007, 03:33 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. binary decimal conversion
    By eerok in forum C Programming
    Replies: 2
    Last Post: 01-24-2006, 08:51 PM
  5. Help with decimal to hexidecimal program
    By CheeseMonkey in forum C++ Programming
    Replies: 1
    Last Post: 12-22-2001, 02:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21