Like Tree1Likes
  • 1 Post By GReaper

Program BCD to Hex and Hex to BCD

This is a discussion on Program BCD to Hex and Hex to BCD within the C Programming forums, part of the General Programming Boards category; Hi, I need to know how to convert BCD to hex and Hex to BCD. Thanks in advance......

  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
    1,832
    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

    Jeffrey Peter likes this.
    Devoted my life to programming...

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,786
    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
    1,832
    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, 03: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, 12:11 PM

Tags for this Thread


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