Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. checking the validity of hex?

checking the validity of hex?

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    namaskaaram
    wrote on last edited by
    #1

    given a string containing hex,is there any function that checks if teh given string holds a valid hex value? cheerz!

    R K 2 Replies Last reply
    0
    • N namaskaaram

      given a string containing hex,is there any function that checks if teh given string holds a valid hex value? cheerz!

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      Not directly. It's fairly easy to write one though. Just check that there is nothing other than 0-9 or A-F in the string.

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      B 1 Reply Last reply
      0
      • N namaskaaram

        given a string containing hex,is there any function that checks if teh given string holds a valid hex value? cheerz!

        K Offline
        K Offline
        kakan
        wrote on last edited by
        #3

        AFAIK, there is no way to check a whole string for valid hexadecial values, but you can make a loop and check each character one by one. Have a look at one of the isxdigit functions.

        1 Reply Last reply
        0
        • R Ryan Binns

          Not directly. It's fairly easy to write one though. Just check that there is nothing other than 0-9 or A-F in the string.

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          And a-f People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks

          R 1 Reply Last reply
          0
          • B Blake Miller

            And a-f People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks

            R Offline
            R Offline
            Ryan Binns
            wrote on last edited by
            #5

            Blake Miller wrote:

            And a-f

            I assumed he had at least some level of intelligence...

            Ryan

            "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

            B 1 Reply Last reply
            0
            • R Ryan Binns

              Blake Miller wrote:

              And a-f

              I assumed he had at least some level of intelligence...

              Ryan

              "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

              B Offline
              B Offline
              Blake Miller
              wrote on last edited by
              #6

              Given the nature of the original question, I chose not to make any assumptions. We actually had production code similar to the following (greatly paraphrased)... // check for ascii characters... if( cChar > 'a' && cChar < 'z' ){ ... blah blah blah... } I suppose you can already see what is wrong with that, even if they were only looking for lower case characters... People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups