Thread: Program BCD to Hex and Hex to BCD

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    2

    Program BCD to Hex and Hex to BCD

    Hi, I need to know how to convert BCD to hex and Hex to BCD. Thanks in advance...

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Your best bet is:
    If BCD -> Hex : Convert BCD to Decimal, then that to Hex
    If Hex -> BCD : Convert Hex to Decimal, then that to BCD

    Devoted my life to programming...

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Can't you just do the conversions directly by the use of lookup tables?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by laserlight View Post
    Can't you just do the conversions directly by the use of lookup tables?
    I don't think so, because here's an example:
    12(10) = 1100(2) = C(16) = 00010010(BCD)
    If you wanted just to print it though, yes it would be the easiest thing to do.
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Sep 2012
    Posts
    2
    Thanks GReaper I have finished the program....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-16-2010, 10:17 AM
  2. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  3. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  4. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  5. Replies: 18
    Last Post: 11-13-2006, 01:11 PM

Tags for this Thread