home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / MAPBIT.ICN < prev    next >
Text File  |  1991-07-13  |  2KB  |  54 lines

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