home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pmafire!news.dell.com!swrinde!gatech!news.ans.net!cmcl2!adm!news
- From: stone@hilbert.math.grin.edu (John David Stone)
- Newsgroups: comp.lang.pascal
- Subject: What is "shr" and "shl" ???
- Message-ID: <35196@adm.brl.mil>
- Date: 23 Jan 93 21:09:30 GMT
- Sender: news@adm.brl.mil
- Lines: 28
-
-
- shr and shl treat their left operand, an integer, as a bit pattern,
- and shift the bit pattern right or left respectively, by the number of
- positions indicated by the second operand.
-
- On a sixteen-bit machine using the twos-complement representation,
- for instance, the integer 19 would be represented as
-
- 0000000000010011
-
- so that 19 shl 5 would be
-
- 0000001001100000
-
- (that is, 608), and 19 shr 3 would be
-
- 0000000000000010
-
- (that is, 2). These operators are used for doing fast multiplications or
- divisions by exact powers of two, or for manipulating a group of single-bit
- flags packed into an integer value to save space.
-
- shr and shl are non-standard and non-portable.
-
- ------ John David Stone - Lecturer in Computer Science and Philosophy -----
- -------------- Manager of the Mathematics Local-Area Network --------------
- -------------- Grinnell College - Grinnell, Iowa 50112 - USA --------------
- -------- stone@math.grin.edu - (515) 269-3181 - stone@grin1.bitnet --------
-