home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / C_DISK5.ZIP / MICROCAD / MSCURSOR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-26  |  1.0 KB  |  38 lines

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