Thread: help with hex to dec converter ??

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    help with hex to dec converter ??

    hello there ,, ^_^

    i need help with this,,, i can't get it ,, i don't know y ,, maybe because i can't create a function can convert from something to other ,, ^_^

    i really need your help with this one ,, ^_^

    btw i am new here and kindda like it ,, ^_^

    Write a program that able to convert Hex number to decimal and vice versa. The program should
    have two functions. The first function called hexToDec takes one argument as string and returns
    an integer. The second function called decToHex takes also one argument as integer and returns
    a string. The program should offer the user two options:
    1. To convert Hex to Dec.
    2. To convert Dec to Hex.
    Example:
    Please choose one of the following:
    1- Convert Hex to Dec.
    2- Convert Dec to Hex.
    1
    Please enter a Hex number:
    2A
    2A = 42 in Decimal.
    ====================================
    Please choose one of the following:
    1- Convert Hex to Dec.
    2- Convert Dec to Hex.
    2
    Please enter a Dec number:
    2748
    2748 = ABC in Hex.
    Assume that all Letters are in capital letters so you do not need to worry about small letters too.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Do you yourself (without mechanical aids except perhaps a four-function calculator) know how to convert 2748 to hexadecimal?

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    2
    i know how to convert it on a paper but i don't know how to write it as a program ,, ??

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, that's the catch: they're exactly the same. However you do it on paper, that's how you have your program do it. So if you can write your steps down in order, you'll have pseudocode; and you can then turn that pseudocode into a function. So start by writing your process down, and be as clear as you can.

  5. #5
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by XWR-AiA View Post
    i know how to convert it on a paper but i don't know how to write it as a program ,, ??
    What programming classes have you had? I am not being facetious; this is a core and very basic task in programming and hence there are 101 ways of doing it (assembly, C, C++, etc). Do you know how to create functions in general? That might be a place to start. If you want to cheat, google for snippets.org and dig around there; I promise you will find what you need but you won't learn anything unless you do it yourself...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal to Hex Converter
    By rocketman03 in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:50 AM
  2. Replies: 18
    Last Post: 03-26-2008, 09:01 AM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. converting hex to dec
    By jibbles in forum C Programming
    Replies: 20
    Last Post: 08-07-2004, 11:40 PM
  5. Hex converter?
    By Nasimov in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2003, 01:44 PM