View Single Post
Re: Time to make some decisions?
Old
  (#58)
sfx1999
Member
 
sfx1999's Avatar
 
Status: Offline
Posts: 534
Join Date: Jan 2004
Location: Pittsburgh, PA, USA
Default Re: Time to make some decisions? - 12-06-2004

Quote:
Originally Posted by Pierre-Marie Baty
Yes, what you mean is a bitmask variable.
Yeah that is such a great idea. To bad it took me 2 years to figure out how adminmod knew which one's were on.

Here is an example (tested to work with http://nickciske.com/tools/binary.php). WARNING: may be endian dependant!

Code:
#include <iostream>
 #include <stdlib.h>
 
 #define BIT0 1
 #define BIT1 2
 #define BIT2 4
 #define BIT3 8
 #define BIT4 16
 #define BIT5 32
 #define BIT6 64
 #define BIT7 128
 
 using namespace std;
 
 int main(void)
 {
   char AsciiStorageArray[256];
   cout << "Insert the phrase to be translated: ";
   cin.getline(AsciiStorageArray, 255);
   cout << endl << "Streaming: ";
   
   int i;
   for (i=0; i < 256; i++)
   {
 	if (AsciiStorageArray[i] == 0)
 	  break;
 	if (AsciiStorageArray[i] & BIT7)
 	  cout << 1;
 	else
 	  cout << 0;
 	if (AsciiStorageArray[i] & BIT6)
 	  cout << 1;
 	else
 	  cout << 0;
 	if (AsciiStorageArray[i] & BIT5)
 	  cout << 1;
 	else
 	  cout << 0;
 	if (AsciiStorageArray[i] & BIT4)
 	  cout << 1;
 	else
 	  cout << 0;
 	if (AsciiStorageArray[i] & BIT3)
 	  cout << 1;
 	else
 	  cout << 0;
 	if (AsciiStorageArray[i] & BIT2)
 	  cout << 1;
 	else
 	  cout << 0;
 	if (AsciiStorageArray[i] & BIT1)
 	  cout << 1;
 	else
 	  cout << 0;
 	if (AsciiStorageArray[i] & BIT0)
 	  cout << 1;
 	else
 	  cout << 0;
 	cout << " ";
   }
   
   cout << endl << "Thank you and have a very safe day" << endl;
   
   system("PAUSE");	
   return 0;
 }
Hooray for bit manipulation!
  
Reply With Quote