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

  1. ############################################################################
  2. #
  3. #    Name:    signed.icn
  4. #
  5. #    Title:    Puts bits of characters of a string into an integer
  6. #
  7. #    Author:    Robert J. Alexander
  8. #
  9. #    Date:    April 2, 1990
  10. #
  11. ############################################################################
  12. #
  13. #  signed(s,n) -- Puts raw bits of characters of string s into an
  14. #  integer.  The value is taken as signed.
  15. #
  16. #  If large integers are supported, this routine will work for integers
  17. #  of arbitrary size.
  18. #
  19. #  If large integers are not supported, the following are true:
  20. #
  21. #    If the size of s is the same as or greater than the size of an
  22. #    integer in the Icon implementation, the result will be negative or
  23. #    positive depending on the value of the integer's sign bit.
  24. #
  25. #    If the size of s is less than the size of an integer, the bytes are
  26. #    put into the low order part of the integer, with the remaining high
  27. #    order bytes filled with sign bits (the high order bit of the first
  28. #    character of the string).  If the string is too large, the most
  29. #    significant bytes will be lost.
  30. #
  31. #  This procedure is normally used for processing of binary data read
  32. #  from a file.
  33. #
  34.  
  35. procedure signed(s)
  36.    local i
  37.    i := if ord(s[1]) >= 128 then -1 else 0
  38.    every i := ior(ord(!s),ishift(i,8))
  39.    return i
  40. end
  41.