home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / pascal / 8477 < prev    next >
Encoding:
Internet Message Format  |  1993-01-24  |  1.4 KB

  1. Path: sparky!uunet!pmafire!news.dell.com!swrinde!gatech!news.ans.net!cmcl2!adm!news
  2. From: stone@hilbert.math.grin.edu (John David Stone)
  3. Newsgroups: comp.lang.pascal
  4. Subject: What is "shr" and "shl" ???
  5. Message-ID: <35196@adm.brl.mil>
  6. Date: 23 Jan 93 21:09:30 GMT
  7. Sender: news@adm.brl.mil
  8. Lines: 28
  9.  
  10.  
  11.         shr and shl treat their left operand, an integer, as a bit pattern,
  12. and shift the bit pattern right or left respectively, by the number of
  13. positions indicated by the second operand.
  14.  
  15.         On a sixteen-bit machine using the twos-complement representation,
  16. for instance, the integer 19 would be represented as
  17.  
  18.                              0000000000010011
  19.  
  20. so that 19 shl 5 would be
  21.  
  22.                              0000001001100000
  23.  
  24. (that is, 608), and 19 shr 3 would be
  25.  
  26.                              0000000000000010
  27.  
  28. (that is, 2).  These operators are used for doing fast multiplications or
  29. divisions by exact powers of two, or for manipulating a group of single-bit
  30. flags packed into an integer value to save space.
  31.  
  32.         shr and shl are non-standard and non-portable.
  33.  
  34. ------  John David Stone - Lecturer in Computer Science and Philosophy  -----
  35. --------------  Manager of the Mathematics Local-Area Network  --------------
  36. --------------  Grinnell College - Grinnell, Iowa 50112 - USA  --------------
  37. --------  stone@math.grin.edu - (515) 269-3181 - stone@grin1.bitnet  --------
  38.