DECLARE FUNCTION Int2Str$ (intval AS INTEGER)
'$INCLUDE: 'incutil.bi'

CONST true = -1, False = 0

FUNCTION AscCnt% (a AS INTEGER, str AS STRING)
  STATIC n AS INTEGER: n = 0
  STATIC ofs AS INTEGER
  STATIC i AS INTEGER

  DEF SEG = VARSEG(str)
    FOR i = 1 TO LEN(str)
      IF PEEK(ofs + i) = a THEN n = n + 1
    NEXT
  DEF SEG
  AscCnt = n
  
END FUNCTION

'
'  Unfinished !!!! DO NOT USE
'
FUNCTION Int2Str$ (intval AS INTEGER) STATIC
  DIM n AS INTEGER
  DIM tmpint AS INTEGER
  DIM cnt AS INTEGER
  DIM t$

  tmpint = intval
  cnt = 0

  DO
    n = tmpint \ 10
    
    cnt = cnt + 1
  LOOP UNTIL tmpint = 0


END FUNCTION

FUNCTION IsPowerOf2% (BYVAL intval AS LONG)
    DIM ExpOf2 AS LONG
    DIM n AS INTEGER

    IsPowerOf2 = False

    IF intval = 0 THEN EXIT FUNCTION

    IF ((intval AND (intval - 1))) = 0 THEN
       IF intval = 1 THEN IsPowerOf2 = 0: EXIT FUNCTION
       ExpOf2 = 1
       FOR n = 2 TO 31
           ExpOf2 = ExpOf2 * 2
           IF intval = ExpOf2 THEN IsPowerOf2 = n - 1: EXIT FUNCTION
       NEXT
    END IF

END FUNCTION

FUNCTION Trim$ (t AS STRING)

    Trim$ = LTRIM$(RTRIM$(t))

END FUNCTION

