[comp.lang.icon] Correction to packed decimal converter

tenaglia@mis.mcw.edu (Chris Tenaglia - 257-8765) (01/24/90)

Several weeks ago I posted procedures for converting integers to and
from packed format. After perfecting an application using them, a flaw
became apparent in the procedure unpack(). Below is the corrected version.

##################################################################
#                                                                #
# THIS PROCEDURE UNPACKS A VALUE INTO AN INTEGER.                #
#                                                                #
##################################################################
procedure unpack(val,width)         # REQUIRES LINK RADCON !
  local tmp,number,tens,ones,sign
  tmp  := ""
  sign := 1
  every number := ord(!val) do
    tmp ||:= right(map(radcon(number,10,16),&lcase,&ucase),2,"0") #this line changed
  if tmp[-1] == ("B" | "D") then sign := -1
  tmp[-1] := ""
  tmp    *:= sign
  /width  := *tmp
  return right(tmp,width)
  end

Yours truly,

Chris Tenaglia (System Manager)
Medical College of Wisconsin
8701 W. Watertown Plank Rd.
Milwaukee, WI 53226
(414)257-8765
tenaglia@mis.mcw.edu