home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 24.13 Iee2real()
- Author: Joe Booth
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- //───── NOTE: must compile with the /N option!
-
- function Iee2real(cIee)
- LOCAL retval:=0,k,x1:="",sign,exponent,fraction
- if cIee <> repl(chr(0),8) // Are all bits set to zero?
- for k=len(cIee) to 1 step -1
- x1 += Dec2bin(asc(Substr(cIee,k,1)))
- next
- sign := (Substr(x1,1,1)="1")
- exponent := Bin2dec(Substr(x1,2,11)) - 1022
- fraction := Bin2dec("1"+Substr(x1,13),.T.)
- retval := if(sign,-1,1)* (fraction * (2**exponent))
- endif
- return retval
-
- function Bin2dec(_string)
- LOCAL retval :=0 ,k
- for k=1 to len(_string)
- retval := If(Substr(_string,k,1)="0",0,1)+retval+retval
- next
- return retval
-
- function Dec2bin(_number)
- LOCAL tmp := _number,retval:="",remd,quot
- while .T.
- quot := int(tmp/2)
- remd := abs(tmp)-2*abs(quot)
- retval:= Substr("01",remd+1,1)+retval
- if quot= 0
- exit
- endif
- tmp := quot
- enddo
- while len(retval)<16
- retval:="0"+retval
- enddo
- return retval
-
- // end of file CHP2413.PRG
-