FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
str_convfrom_rad.c
Go to the documentation of this file.
1
#include "
fb.h
"
2
3
FBCALL
int
fb_hStrRadix2Int
(
char
*src, ssize_t len,
int
radix )
4
{
5
int
c, v;
6
7
v = 0;
8
9
switch
( radix )
10
{
11
/* hex */
12
case
16:
13
while
( --len >= 0 )
14
{
15
c = *src++;
16
if
( (c >= 97) && (c <= 102) )
17
c -= 87;
18
else
if
( (c >= 65) && (c <= 70) )
19
c -= 55;
20
else
if
( (c >= 48) && (c <= 57) )
21
c -= 48;
22
else
23
break
;
24
25
v = (v * 16) + c;
26
}
27
break
;
28
29
/* oct */
30
case
8:
31
while
( --len >= 0 ) {
32
c = *src++;
33
if
( (c >= 48) && (c <= 55) )
34
v = (v * 8) + (c - 48);
35
else
36
break
;
37
}
38
break
;
39
40
/* bin */
41
case
2:
42
while
( --len >= 0 ) {
43
c = *src++;
44
if
( (c >= 48) && (c <= 49) )
45
v = (v * 2) + (c - 48);
46
else
47
break
;
48
}
49
break
;
50
51
default
:
52
break
;
53
}
54
55
return
v;
56
}
rtlib
str_convfrom_rad.c
Generated on Thu Jan 23 2014 19:40:12 for FreeBASIC by
1.8.4