home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / procs / mapbit.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  58 lines

  1. ############################################################################
  2. #
  3. #    File:     mapbit.icn
  4. #
  5. #    Subject:  Procedures to map string into bit representation
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     December 5, 1995
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #     The procedure mapbit(s) produces a string of zeros and ones
  18. #  corresponding to the bit patterns for the characters of s.  For
  19. #  example, mapbit("Axe") produces "010000010111100001100101".
  20. #
  21. ############################################################################
  22. #
  23. #  Links: strings
  24. #
  25. ############################################################################
  26.  
  27. link strings
  28.  
  29. procedure bilit(text,alpha,first,second)
  30.    return collate(map(text,alpha,first),map(text,alpha,second))
  31. end
  32.  
  33. procedure mapbit(s)
  34.    static all, base16, hex1, hex2, quad1, quad2, pair1, pair2
  35.  
  36.    #  The following is a bit ornate, but then ... .  It could be
  37.    #  made more compact (and cryptic) by using lists of templates
  38.    #  and parameterizing the initialization.
  39.  
  40.    initial {
  41.       all := string(&cset)
  42.       base16 := "0123456789ABCDEF"
  43.       hex1 := ""
  44.       every hex1 ||:= repl(!base16,16)
  45.       hex2 := repl(base16,16)
  46.       quad1 := ""
  47.       every quad1 ||:= repl(!left(base16,4),4)
  48.       quad2 := repl(left(base16,4),4)
  49.       pair1 := ""
  50.       every pair1 ||:= repl(!left(base16,2),2)
  51.       pair2 := repl(left(base16,2),2)
  52.       }
  53.  
  54.    s := bilit(bilit(bilit(s,all,hex1,hex2),base16,quad1,quad2),left(base16,4),
  55.            pair1,pair2)
  56.    return s
  57. end
  58.