home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / Word8.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  5.5 KB  |  152 lines  |  [TEXT/Moml]

  1. (* Word8 -- SML Basis Library *)
  2.  
  3. type word = word8
  4. val wordSize : int
  5.  
  6. val orb  : word * word -> word
  7. val andb : word * word -> word
  8. val xorb : word * word -> word
  9. val notb : word -> word
  10.  
  11. val <<  : word * Word.word -> word
  12. val >>  : word * Word.word -> word
  13. val ~>> : word * Word.word -> word
  14.  
  15. val +   : word * word -> word
  16. val -   : word * word -> word
  17. val *   : word * word -> word
  18. val div : word * word -> word
  19. val mod : word * word -> word
  20.  
  21. val >   : word * word -> bool
  22. val <   : word * word -> bool
  23. val >=  : word * word -> bool
  24. val <=  : word * word -> bool
  25. val compare : word * word -> order
  26.  
  27. val min : word * word -> word
  28. val max : word * word -> word
  29.  
  30. val toString   : word -> string
  31. val fromString : string -> word option
  32. val scan : StringCvt.radix 
  33.            -> (char, 'a) StringCvt.reader -> (word, 'a) StringCvt.reader
  34. val fmt  : StringCvt.radix -> word -> string
  35.  
  36. val toInt   : word -> int
  37. val toIntX  : word -> int        (* with sign extension *)
  38. val fromInt : int -> word
  39.  
  40. val toLargeInt   : word -> int
  41. val toLargeIntX  : word -> int        (* with sign extension *)
  42. val fromLargeInt : int -> word
  43.  
  44. val toLargeWord   : word -> Word.word
  45. val toLargeWordX  : word -> Word.word    (* with sign extension *)
  46. val fromLargeWord : Word.word -> word
  47.  
  48. (* [word] is the type of 8-bit words, or 8-bit unsigned integers in
  49.    the range 0..255.
  50.  
  51.    [wordSize] is 8.
  52.  
  53.    [orb(w1, w2)] returns the bitwise `or' of w1 and w2.
  54.  
  55.    [andb(w1, w2)] returns the bitwise `and' of w1 and w2.
  56.  
  57.    [xorb(w1, w2)] returns the bitwise `exclusive or' or w1 and w2.
  58.  
  59.    [notb w] returns the bitwise negation of w.
  60.  
  61.    [<<(w, k)] returns the word resulting from shifting w left by k
  62.    bits.  The bits shifted in are zero, so this is a logical shift.
  63.    Consequently, the result is 0-bits when k >= wordSize.
  64.  
  65.    [>>(w, k)] returns the word resulting from shifting w right by k
  66.    bits.  The bits shifted in are zero, so this is a logical shift.
  67.    Consequently, the result is 0-bits when k >= wordSize.
  68.  
  69.    [~>>(w, k)] returns the word resulting from shifting w right by k
  70.    bits.  The bits shifted in are replications of the left-most bit:
  71.    the `sign bit', so this is an arithmetical shift.  Consequently,
  72.    for k >= wordSize and wordToInt w >= 0 the result is all 0-bits, and 
  73.    for k >= wordSize and wordToInt w <  0 the result is all 1-bits.
  74.  
  75.    To make <<, >>, and ~>> infix, use the declaration:
  76.                           infix 5 << >> ~>>
  77.  
  78.    [+, -, *, div, mod] represent unsigned integer addition,
  79.    subtraction, multiplication, division, and remainder, modulus 256.
  80.    The operations (i div j) and (i mod j) raise Div when j = 0.
  81.    Otherwise no exceptions are raised.
  82.  
  83.    [w1 > w2] returns true if the unsigned integer represented by w1
  84.    is larger than that of w2, and similarly for <, >=, <=.  
  85.  
  86.    [compare(w1, w2)] returns LESS, EQUAL, or GREATER, according 
  87.    as w1 is less than, equal to, or greater than w2 (as unsigned integers).
  88.  
  89.    [min(w1, w2)] returns the smaller of w1 and w2 (as unsigned integers).
  90.  
  91.    [max(w1, w2)] returns the larger of w1 and w2 (as unsigned integers).
  92.  
  93.    [fmt radix w] returns a string representing w, in the radix (base)
  94.    specified by radix.
  95.  
  96.      radix    description                     output format  
  97.      ------------------------------------------------------  
  98.       BIN     unsigned binary      (base  2)  [01]+         
  99.       OCT     unsigned octal       (base  8)  [0-7]+          
  100.       DEC     unsigned decimal     (base 10)  [0-9]+          
  101.       HEX     unsigned hexadecimal (base 16)  [0-9A-F]+       
  102.  
  103.    [toString w] returns a string representing w in unsigned
  104.    hexadecimal format.  Equivalent to (fmt HEX w).
  105.    
  106.    [fromString s] returns SOME(w) if a hexadecimal unsigned numeral
  107.    can be scanned from a prefix of string s, ignoring any initial
  108.    whitespace; returns NONE otherwise.  Raises Overflow if the scanned
  109.    number cannot be represented as a word.  An unsigned hexadecimal
  110.    numeral must have form, after possible initial whitespace:
  111.        [0-9a-fA-F]+
  112.  
  113.    [scan radix {getc} charsrc] attempts to scan an unsigned numeral
  114.    from the character source charsrc, using the accessor getc, and
  115.    ignoring any initial whitespace.  The radix argument specifies the
  116.    base of the numeral (BIN, OCT, DEC, HEX).  If successful, it
  117.    returns SOME(w, rest) where w is the value of the numeral scanned,
  118.    and rest is the unused part of the character source.  Raises
  119.    Overflow if the scanned number cannot be represented as a word.  A
  120.    numeral must have form, after possible initial whitespace:
  121.  
  122.      radix    input format 
  123.      -------------------------------------
  124.       BIN     (0w)?[0-1]+
  125.       OCT     (0w)?[0-7]+
  126.       DEC     (0w)?[0-9]+
  127.       HEX     (0wx|0wX|0x|0X)?[0-9a-fA-F]+
  128.  
  129.    [toInt w] returns the integer in the range 0..255 represented by w.
  130.  
  131.    [toIntX w] returns the signed integer (in the range ~128..127) 
  132.    represented by bit-pattern w.
  133.    
  134.    [fromInt i] returns the word holding the 8 least significant bits of i.
  135.  
  136.    [toLargeInt w] returns the integer in the range 0..255 represented by w.
  137.  
  138.    [toLargeIntX w] returns the signed integer (in the range ~128..127) 
  139.    represented by bit-pattern w.
  140.    
  141.    [fromLargeInt i] returns the word holding the 8 least significant bits of i.
  142.  
  143.    [toLargeWord w] returns the Word.word value corresponding to w.
  144.  
  145.    [toLargeWordX w] returns the Word.word value corresponding to w,
  146.    with sign extension.  That is, the 8 least significant bits of the
  147.    result are those of w, and the remaining bits are all equal to the
  148.    most significant bit of w: its `sign bit'.
  149.  
  150.    [fromLargeWord w] returns w modulo 256.
  151. *)
  152.