home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_44.arc / MICROCAD.ARC / MSCURSOR.CPP < prev    next >
Text File  |  1988-09-27  |  1KB  |  39 lines

  1. // Figure 13 for "A Little CAD with C++"
  2. // Copyright 1988 Bruce Eckel
  3. // Permission required to distribute source
  4.  
  5. // file: mscursor.cpp
  6. /* Given a bitmap of ASCII ones and zeros,
  7.    mscursor < bitmap > outfile.cur
  8.    generates a structure for a new mouse
  9.    cursor, with the bitmap as a comment
  10.    block.  This shows how useful streams
  11.    can be. */
  12. #include <stream.hpp>
  13.  
  14. main() {
  15. char binary[20]; // holds the source pattern
  16. unsigned int positive[16];
  17. unsigned int j; int x = 0;
  18. cout << "int NAME[] = {\n";
  19. while(cin.good()) {
  20.     cin >> binary;
  21.     j = 0; 
  22.     // note the '<<' operator has a different
  23.     // meaning depending on what context it is
  24.     // being used in:
  25.     for (int i = 0, k = 15; i < 16; i++, k-- )
  26.         j |= (binary[i] == '1') ? (1 << k) : 0;
  27.     // streams allow easy writing of hex:
  28.     cout << "0x" << hex(~j) << 
  29.        ",\t\t/* " << binary << " */\n";
  30.     positive[x++] = j; 
  31.     if (x > 15) break;
  32. }
  33. for (int i = 0; i < 16; i++) {
  34.     cout << "0x" << hex(positive[i]) << ", ";
  35.     if ( i == 8) cout << "\n";
  36. }
  37. cout << "\n};\n\n";
  38. }
  39.