home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!elroy.jpl.nasa.gov!lambda.msfc.nasa.gov!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!unet.umn.edu!fin
- From: fin@unet.umn.edu (Craig A. Finseth)
- Subject: Re: why does #define Ctrl(c) c&037 work ?
- Message-ID: <1992Aug13.133959.21908@news2.cis.umn.edu>
- Sender: news@news2.cis.umn.edu (Usenet News Administration)
- Nntp-Posting-Host: norge.unet.umn.edu
- Organization: University of Minnesota, Networking Services.
- References: <1992Aug12.133132.10723@Princeton.EDU> <BRANNON.92Aug12164222@stun4r.cs.caltech.edu>
- Distribution: worrrld
- Date: Thu, 13 Aug 1992 13:39:59 GMT
- Lines: 34
-
- In article <BRANNON.92Aug12164222@stun4r.cs.caltech.edu>, brannon@stun4r.cs.caltech.edu (Terrence M. Brannon) writes:
- |> I am hacking thru the source code for GNU Emacs and I came across
- |> this:
- |> #define Ctl(c) ((c)&037)
- |> and I am wondering why a bitwise-AND of the ASCII value for a chacter
- |> and octal 037 (binary 00111111) would generate the control version of
- |> a printable character.
-
- It works for 32 of the 33 control characters. For example:
-
- A = 65 decimal = 101 octal
-
- and
-
- 101 & 37 = 1
-
- which is ^A. In a similar fashion, it works for @, A-Z, [ \ ] ^ and _.
- It fails for ? (as in ^?, 127 decimal). The "correct" macro should
- be:
-
- #define Ctl(c) ((c)^'@')
-
- Which works for all of the above, and ? too.
-
- On the other hand, the GNU form picks up the lower case letters (as in
- ^a), but I at least would consider that usage to be silly, and
- certainly not worth giving up ^? for.
-
- Craig A. Finseth fin@unet.umn.edu [CAF13]
- Networking Services +1 612 624 3375 desk
- Computer and Information Services +1 612 625 0006 problems
- University of Minnesota +1 612 626 1002 fax
- 130 Lind Hall, 207 Church St SE
- Minneapolis MN 55455-0134, USA
-