diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2013-01-27 23:51:56 +0000 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2013-01-27 23:51:56 +0000 |
commit | 6ab0c0f5bf14ed9c15370407b9ee7e0b4b089ae1 (patch) | |
tree | 926065cf45450116098db664e3c61dced9e1f21a /ipl/procs/bincvt.icn | |
download | icon-6ab0c0f5bf14ed9c15370407b9ee7e0b4b089ae1.tar.gz |
Initial upstream version 9.4.3upstream/9.4.3
Diffstat (limited to 'ipl/procs/bincvt.icn')
-rw-r--r-- | ipl/procs/bincvt.icn | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/ipl/procs/bincvt.icn b/ipl/procs/bincvt.icn new file mode 100644 index 0000000..6a54835 --- /dev/null +++ b/ipl/procs/bincvt.icn @@ -0,0 +1,62 @@ +############################################################################ +# +# File: bincvt.icn +# +# Subject: Procedures to convert binary data +# +# Author: Robert J. Alexander +# +# Date: October 16, 1996 +# +############################################################################ +# +# This file is in the public domain. +# +############################################################################ +# +# unsigned() -- Converts binary byte string into unsigned integer. +# Detects overflow if number is too large. +# +# This procedure is normally used for processing of binary data +# read from a file. +# +# raw() -- Puts raw bits of characters of string s into an integer. If +# the size of s is less than the size of an integer, the bytes are put +# into the low order part of the integer, with the remaining high order +# bytes filled with zero. If the string is too large, the most +# significant bytes will be lost -- no overflow detection. +# +# This procedure is normally used for processing of binary data +# read from a file. +# +# rawstring() -- Creates a string consisting of the raw bits in the low +# order "size" bytes of integer i. +# +# This procedure is normally used for processing of binary data +# to be written to a file. +# +############################################################################ + +procedure unsigned(s) + local i + i := 0 + every i := ord(!s) + i * 256 + return i +end + +procedure raw(s) + local i + i := 0 + every i := ior(ord(!s),ishift(i,8)) + return i +end + +procedure rawstring(i,size) + local s + s := "" + every 1 to size do { + s := char(iand(i,16rFF)) || s + i := ishift(i,-8) + } + return s +end |