3 /* 10進数の文字列をWORD値に変換 */
4 WORD n2word(const char *str)
6 assert(isdigit(*str) || *str == '-');
10 n = strtol(str, &check, 10);
12 setcerr(114, str); /* not integer */
15 /* nが-32768〜32767の範囲にないときは、その下位16ビットを格納 */
16 if(n < -32768 || n > 32767) {
22 /* 16進数の文字列をWORD値に変換 */
23 WORD h2word(const char *str)
29 if(*str == '-' || strlen(str) > 4) {
30 setcerr(116, str-1); /* out of hex range */
34 w = (WORD)strtol(str, &check, 16);
36 setcerr(115, str-1); /* not hex */
42 /* 10進数または16進数の文字列をWORD値に変換 */
43 WORD a2word(const char *str)
46 if(!isdigit(*str) && *str != '-' && *str != '#') {
47 setcerr(114, str); /* not integer */
58 /* WORD値を10進数の文字列に変換 */
59 char *word2n(WORD word)
61 char *p = malloc(6), *q = malloc(6);
64 *(p + i++) = word % 10 + '0';
65 } while((word /= 10) > 0);
66 for(j = 0; j < i; j++) {
67 *(q + j) = *(p + (i - 1) - j);
73 /* WORD値を2進数の文字列に変換 */
74 char *word2bit(const WORD word)
81 *p++ = (word & mask) ? '1' : '0';
82 } while((mask >>= 1) > 0);