diff options
Diffstat (limited to 'ipl/procs/mapbit.icn')
-rw-r--r-- | ipl/procs/mapbit.icn | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/ipl/procs/mapbit.icn b/ipl/procs/mapbit.icn new file mode 100644 index 0000000..86286b3 --- /dev/null +++ b/ipl/procs/mapbit.icn @@ -0,0 +1,57 @@ +############################################################################ +# +# File: mapbit.icn +# +# Subject: Procedures to map string into bit representation +# +# Author: Ralph E. Griswold +# +# Date: December 5, 1995 +# +############################################################################ +# +# This file is in the public domain. +# +############################################################################ +# +# The procedure mapbit(s) produces a string of zeros and ones +# corresponding to the bit patterns for the characters of s. For +# example, mapbit("Axe") produces "010000010111100001100101". +# +############################################################################ +# +# Links: strings +# +############################################################################ + +link strings + +procedure bilit(text,alpha,first,second) + return collate(map(text,alpha,first),map(text,alpha,second)) +end + +procedure mapbit(s) + static all, base16, hex1, hex2, quad1, quad2, pair1, pair2 + + # The following is a bit ornate, but then ... . It could be + # made more compact (and cryptic) by using lists of templates + # and parameterizing the initialization. + + initial { + all := string(&cset) + base16 := "0123456789ABCDEF" + hex1 := "" + every hex1 ||:= repl(!base16,16) + hex2 := repl(base16,16) + quad1 := "" + every quad1 ||:= repl(!left(base16,4),4) + quad2 := repl(left(base16,4),4) + pair1 := "" + every pair1 ||:= repl(!left(base16,2),2) + pair2 := repl(left(base16,2),2) + } + + s := bilit(bilit(bilit(s,all,hex1,hex2),base16,quad1,quad2),left(base16,4), + pair1,pair2) + return s +end |