home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12275 < prev    next >
Encoding:
Text File  |  1992-08-13  |  1.7 KB  |  48 lines

  1. Newsgroups: comp.lang.c
  2. 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
  3. From: fin@unet.umn.edu (Craig A. Finseth)
  4. Subject: Re: why does #define Ctrl(c) c&037 work ?
  5. Message-ID: <1992Aug13.133959.21908@news2.cis.umn.edu>
  6. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  7. Nntp-Posting-Host: norge.unet.umn.edu
  8. Organization: University of Minnesota, Networking Services.
  9. References: <1992Aug12.133132.10723@Princeton.EDU> <BRANNON.92Aug12164222@stun4r.cs.caltech.edu>
  10. Distribution: worrrld
  11. Date: Thu, 13 Aug 1992 13:39:59 GMT
  12. Lines: 34
  13.  
  14. In article <BRANNON.92Aug12164222@stun4r.cs.caltech.edu>, brannon@stun4r.cs.caltech.edu (Terrence M. Brannon) writes:
  15. |> I am hacking thru the source code for GNU Emacs and I came across
  16. |> this:
  17. |> #define Ctl(c) ((c)&037)
  18. |> and I am wondering why a bitwise-AND of the ASCII value for a chacter
  19. |> and octal 037 (binary 00111111) would generate the control version of
  20. |> a printable character.
  21.  
  22. It works for 32 of the 33 control characters.  For example:
  23.  
  24.     A = 65 decimal = 101 octal
  25.  
  26. and
  27.  
  28.     101 & 37 = 1
  29.  
  30. which is ^A. In a similar fashion, it works for @, A-Z, [ \ ] ^ and _.
  31. It fails for ? (as in ^?, 127 decimal).  The "correct" macro should
  32. be:
  33.  
  34. #define Ctl(c) ((c)^'@')
  35.  
  36. Which works for all of the above, and ? too.
  37.  
  38. On the other hand, the GNU form picks up the lower case letters (as in
  39. ^a), but I at least would consider that usage to be silly, and
  40. certainly not worth giving up ^? for.
  41.  
  42. Craig A. Finseth            fin@unet.umn.edu [CAF13]
  43. Networking Services            +1 612 624 3375 desk
  44. Computer and Information Services    +1 612 625 0006 problems
  45. University of Minnesota            +1 612 626 1002 fax
  46. 130 Lind Hall, 207 Church St SE
  47. Minneapolis MN 55455-0134, USA
  48.