1 /* ***********************************************************
 2    *                                                         *
 3    * Copyright, (C) Honeywell Information Systems Inc., 1982 *
 4    *                                                         *
 5    * Copyright (c) 1972 by Massachusetts Institute of        *
 6    * Technology and Honeywell Information Systems, Inc.      *
 7    *                                                         *
 8    *********************************************************** */
 9 
10 
11 /* Procedure to convert string to binary.  String assumed to conform
12    to the syntax [+|-]digit*  */
13 
14 decbin:   proc(string) returns(fixed bin);
15 
16 dcl       string char(*) aligned;
17 
18 dcl       (i,number,sign) fixed bin,
19           c char(1),
20           (binary,length,substr,unspec) builtin;
21 
22           i,sign = 1;
23           c = substr(string,1,1);
24           if c = "+" then i = 2;
25      else if c = "-" then do; i = 2; sign = -1; end;
26 
27           number = 0;
28           do i = i to length(string);
29                c = substr(string,i,1);
30                number = number * 10 + binary(unspec(c),9) - 48;
31                end;
32 
33           return(sign * number);
34           end;