Convert Hex String to an Integer Value.

by Jun 7, 1996

 Technical Information Database

TI2203C.txt   Convert Hex String to an Integer Value.
Category   :General
Platform    :All
Product    :C/C++  All

Description:
This document provides a method to read hexadecimal numbers.
The atoi() function ignores the A-F digits in a hexadecimal
number.  In fact, the first non-digit character in the string
passed to atoi() ends the conversion.
The following example converts a four-character text string that
represents a hexadecimal number into an integer.  It can be used
as a template to create other ASCII-to-number conversions.
The example code defines a CC++ function called axtoi() that
does the conversion.  It includes a short main() that to test the
function.
#include 
int axtoi(char *hexStg) {
  int n = 0;         // position in string
  int m = 0;         // position in digit[] to shift
  int count;         // loop index
  int intValue = 0;  // integer value of hex string
  int digit[5];      // hold values to convert
  while (n  0x29 && hexStg[n] ='a' && hexStg[n] ='A' && hexStg[n] <<<<'s Evaluate|Modify. dialog you can and see how the ANDs,
ORs, and shifts work to find the value of each character in the
string.
CAVEATS
=======
N/A
BIBLIOGRAPHY
============
N/A


Reference:


7/2/98 10:40:41 AM

Article originally contributed by