Author: Embarcadero USA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
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
Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition