Mercurial > octave
comparison scripts/strings/hex2dec.m @ 3426:f8dde1807dee
[project @ 2000-01-13 08:40:00 by jwe]
author | jwe |
---|---|
date | Thu, 13 Jan 2000 08:40:53 +0000 |
parents | 4f40efa995c1 |
children | 2a257be5e488 |
comparison
equal
deleted
inserted
replaced
3425:8625164a0a39 | 3426:f8dde1807dee |
---|---|
19 | 19 |
20 ## -*- texinfo -*- | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} hex2dec (@var{s}) | 21 ## @deftypefn {Function File} {} hex2dec (@var{s}) |
22 ## Return the decimal number corresponding to the hexadecimal number stored | 22 ## Return the decimal number corresponding to the hexadecimal number stored |
23 ## in the string @var{s}. For example, | 23 ## in the string @var{s}. For example, |
24 ## | 24 ## |
25 ## @example | 25 ## @example |
26 ## hex2dec ("12B") | 26 ## hex2dec ("12B") |
27 ## @result{} 299 | 27 ## @result{} 299 |
28 ## hex2dec ("12b") | 28 ## hex2dec ("12b") |
29 ## @result{} 299 | 29 ## @result{} 299 |
43 nr = rows (h); | 43 nr = rows (h); |
44 d = zeros (nr, 1); | 44 d = zeros (nr, 1); |
45 for i = 1:nr | 45 for i = 1:nr |
46 s = h (i, :); | 46 s = h (i, :); |
47 if (isxdigit (s)) | 47 if (isxdigit (s)) |
48 tmp = sscanf (s, "%x"); | 48 tmp = sscanf (s, "%x"); |
49 if (isempty (tmp)) | 49 if (isempty (tmp)) |
50 error ("hex2dec: invalid conversion"); | 50 error ("hex2dec: invalid conversion"); |
51 else | 51 else |
52 d (i) = tmp; | 52 d (i) = tmp; |
53 endif | 53 endif |
54 else | 54 else |
55 error ("hex2dec: argument must be a string of hexadecimal digits"); | 55 error ("hex2dec: argument must be a string of hexadecimal digits"); |
56 endif | 56 endif |
57 endfor | 57 endfor |
58 else | 58 else |
59 error ("hex2dec: expecting a string argument"); | 59 error ("hex2dec: expecting a string argument"); |
60 endif | 60 endif |