--
--	Inmos Libraries
--	Copyright (C) 1988, 1989, 1990, 1991, 1993  Inmos Limited
--
--	This library is free software; you can redistribute it and/or
--	modify it under the terms of the GNU Lesser General Public
--	License as published by the Free Software Foundation; either
--	version 2 of the License, or (at your option) any later version.
--
--	This library is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--	Lesser General Public License for more details.
--
--	You should have received a copy of the GNU Lesser General Public
--	License along with this library; if not, write to the Free Software
--	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
--

--** @module convert

#OPTION "E V" -- no compiler libraries, no vector space
#COMMENT "Type conversion library V1.2 18/01/93"
#COMMENT "(c) Copyright INMOS Limited 1988"
#USE "ioconv.lib"
--{{{  history
-- V1.0, 1-Jul-88
-- Added V to the OPTIONs; V1.1, 22/03/90 SRH
-- Put ValidDigit into an include file, renamed it ValidHexDigit, and
-- converted it into an inline function.  TS/2044, V1.2, 18/01/93 SRH
--}}}
--{{{  STRINGTOHEX64 TA
PROC STRINGTOHEX64 (BOOL Error, INT64 n, VAL []BYTE string)
  --  Empty string behaviour corrected 19.2.88

  []INT n RETYPES n:
  INT chars.scanned:
  INT carry, digit, dump:
  BOOL More :
  #INCLUDE "validch.occ" -- for ValidHexDigit
  SEQ
    n[0] := 0
    n[1] := 0
    Error := FALSE
    chars.scanned := 0
    More := (SIZE string) > 0
    digit := 0
    WHILE More AND (chars.scanned < (SIZE string))
      SEQ
        carry, dump := SHIFTLEFT (0, n[1], 4)
        n[1], n[0]  := SHIFTLEFT (n[1], n[0], 4)
        n[0] := n[0] \/ digit
        Error := Error OR (carry <> 0)
        digit, More := ValidHexDigit (string [chars.scanned])
        chars.scanned := chars.scanned + 1
    IF
      More
        SEQ
          carry, dump := SHIFTLEFT (0, n[1], 4)
          n[1], n[0]  := SHIFTLEFT (n[1], n[0], 4)
          n[0] := n[0] \/ digit
          Error := Error OR (carry <> 0)
      TRUE
        Error := TRUE
:
--}}}
--{{{  HEX64TOSTRING TA
PROC HEX64TOSTRING (INT len, []BYTE string, VAL INT64 n)

  VAL [2]INT n RETYPES n:
  SEQ
    HEXTOSTRING (len, string, n[1])
    HEXTOSTRING (len, [string FROM 8 FOR 8], n[0])
    len := 16
:
--}}}
