{"id":7644,"date":"2026-06-27T00:01:03","date_gmt":"2026-06-27T07:01:03","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7644"},"modified":"2026-06-20T11:37:49","modified_gmt":"2026-06-20T18:37:49","slug":"ctype-function-isxdigit","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7644","title":{"rendered":"Ctype Function: <em>isxdigit()<\/em>"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2026\/05\/ctype.png\" alt=\"\" width=\"400\" height=\"138\" class=\"alignnone size-full wp-image-7590\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2026\/05\/ctype.png 400w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2026\/05\/ctype-300x104.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><br \/>\nThe ctype <em>isxdigit()<\/em> function returns TRUE for any digit you find in a hexadecimal number. I suppose this function has a role to play, most likely in detecting hexadecimal characters in a string. Regardless, this post wraps up my exploration of the <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7542\">ctype functions<\/a>.<br \/>\n<!--more--><br \/>\nHexadecimal values include numbers zero through 9 plus the letters A through F, both upper- and lowercase, to represent values 0 through 15. This counting base (16 or hexadecimal) is common in computerdom as it provides a quick way to reference bits, which are typically arranged in groups of four:<\/p>\n<table>\n<tr>\n<td>Bits<\/td>\n<td>Hex<\/td>\n<td>Decimal<\/td>\n<\/tr>\n<tr>\n<td>0000<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>0001<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>0010<\/td>\n<td>2<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>0011<\/td>\n<td>3<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>0100<\/td>\n<td>4<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>0101<\/td>\n<td>5<\/td>\n<td>5<\/td>\n<\/tr>\n<tr>\n<td>0110<\/td>\n<td>6<\/td>\n<td>6<\/td>\n<\/tr>\n<tr>\n<td>0111<\/td>\n<td>7<\/td>\n<td>7<\/td>\n<\/tr>\n<tr>\n<td>1000<\/td>\n<td>8<\/td>\n<td>8<\/td>\n<\/tr>\n<tr>\n<td>1001<\/td>\n<td>9<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>1010<\/td>\n<td>A<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>1011<\/td>\n<td>B<\/td>\n<td>11<\/td>\n<\/tr>\n<tr>\n<td>1100<\/td>\n<td>C<\/td>\n<td>12<\/td>\n<\/tr>\n<tr>\n<td>1101<\/td>\n<td>D<\/td>\n<td>13<\/td>\n<\/tr>\n<tr>\n<td>1110<\/td>\n<td>E<\/td>\n<td>14<\/td>\n<\/tr>\n<tr>\n<td>1111<\/td>\n<td>F<\/td>\n<td>15<\/td>\n<\/tr>\n<\/table>\n<p>Truly, you can&#8217;t consider yourself a nerd until you know how to count in hex, or can quickly translate hex values such as 0x20 and 0x41 into their decimal equivalents and vice-versa.<\/p>\n<blockquote><p>I went to a restaurant where the waiter wore a shirt with a series of hex values. I don&#8217;t need to tell you that I was only customer ever to read the text those codes represented. (I forget what it said, specifically.) #nerd<\/p><\/blockquote>\n<p>The <em>isxdigit()<\/em> function returns TRUE if the character examined is a number, 0 through 9, uppercase letter, A through Z, or lowercase letter, a through z.<\/p>\n<p>Here is sample code that plows through the printable ASCII code values and plucks out hex digits:<\/p>\n<h3><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2026_06_27-Lesson-a.c\" rel=\"noopener\" target=\"_blank\">2026_06_27-Lesson-a.c<\/a><\/h3>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;ctype.h&gt;\r\n\r\nint main()\r\n{\r\n    int ch;\r\n\r\n    puts(\"X Digits:\");\r\n    <span class=\"comments\">\/* ASCII character range *\/<\/span>\r\n    for( ch=' '; ch&lt;='~'; ch++ )\r\n        if( isxdigit(ch) )\r\n            putchar(ch);\r\n    putchar('\\n');\r\n\r\n    return 0;\r\n}<\/pre>\n<p>The <em>for<\/em> loop runs the gamut of ASCII codes from space through tilde. I could have used the <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7596\"><em>isprint()<\/em> function<\/a> here, but didn&#8217;t want to stack up too many custom ctype functions in my version of the code (below).<\/p>\n<p>In the <em>if<\/em> test, the <em>isxdigit()<\/em> function returns TRUE for a hexadecimal digit, which is output as shown in this sample run:<\/p>\n<pre>X Digits:\r\n0123456789ABCDEFabcdef<\/pre>\n<p>To emulate the <em>isxdigit()<\/em> function, I use a series of <em>if<\/em> tests to weed out the three ranges of ASCII characters found in a hexadecimal value: 0 to 9, A to Z, and a to z:<\/p>\n<h3><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2026_06_27-Lesson-b.c\" rel=\"noopener\" target=\"_blank\">2026_06_27-Lesson-b.c<\/a><\/h3>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdbool.h&gt;\r\n\r\nint isxdigit(int c)\r\n{\r\n    if( c&gt;='0' &amp;&amp; c&lt;='9' )\r\n        return true;\r\n    if( c&gt;='A' &amp;&amp; c&lt;='F' )\r\n        return true;\r\n    if( c&gt;='a' &amp;&amp; c&lt;='f' )\r\n        return true;\r\n\r\n    return false;\r\n}\r\n\r\nint main()\r\n{\r\n    int ch;\r\n\r\n    puts(\"X Digits:\");\r\n    <span class=\"comments\">\/* ASCII character range *\/<\/span>\r\n    for( ch=' '; ch&lt;='~'; ch++ )\r\n        if( isxdigit(ch) )\r\n            putchar(ch);\r\n    putchar('\\n');\r\n\r\n    return 0;\r\n}<\/pre>\n<p>The program&#8217;s output is the same.<\/p>\n<p>To conclude this series, I would comment that the ctype functions don&#8217;t really carry a lot of weight in the Unicode era. It would be nice to see extended ctype functions available that truly understand different locales. Then again, with a knowledge of a programming language like C, you can always code your own functions. Heck, draw up a library! Anything is possible.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>No, the <em>isxdigit<\/em> function doesn&#8217;t identify former digit characters. The &#8220;x&#8221; here refers to hexadecimal. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7644\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-7644","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7644"}],"version-history":[{"count":7,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7644\/revisions"}],"predecessor-version":[{"id":7659,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7644\/revisions\/7659"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}