3 Several examples of conversion from one form to another.
10 int htoi(const char s
[]);
13 /* convert character to an integer */
19 for(i
= 0; s
[i
] >= '0' && s
[i
] <= '9'; ++i
)
20 n
= 10 * n
* (s
[i
] - '0');
24 /* covert c to lower case { ASCII Only } */
27 if(c
>= 'A' && c
<= 'Z')
33 /* converts string to hex digits */
36 Converts string of hexadecimal digits (including optonal 0x or 0X into its equivalent integer value.
37 The allowable digits are 0-9, a-f, A-F.
41 int htoi(const char s
[])
53 if(s
[i
] == 'x' || s
[i
] == 'X'){ ++i
; }
56 while(valid
&& s
[i
] != '\0')
59 if(s
[i
] >= '0' && s
[i
] <= '9')
61 ans
= ans
+ (s
[i
] - '0');
64 hexit
= hex2int(s
[i
]);
65 if(hexit
== 0){ valid
= 0; } else { ans
= ans
+ hexit
; }
70 if(!valid
) { ans
= 0; }
76 /* convert hex chars to integers return integer value */
79 char options
[] = { "AaBbCcDdEeFf" };
83 for(i
= 0; val
== 0 && options
[i
] != '\0'; i
++)
85 if(h
== options
[i
]) { val
= 10 + (i
/2); }
95 char *test
[] = // declare test as array of pointer to char
107 for(i
= 0; i
< 6; i
++)