Expand|Select|Wrap|Line Numbers
- void readByte(unsigned char * buffer, int binarr[])
- {
- unsigned char mask = 1 << 7;
- bool mybit;
- int j =0;
- for ( int i =1; i <= sizeof(binarr) ; i++)
- {
- mybit = (bool) (buffer[j] & mask);
- if (mybit)
- binarr[i] = 1;
- else
- binarr[i] = 0;
- buffer[j]<<=1 ;
- if ( i % 8 == 0)
- j++ ;
- }
- }
here is my main:
Expand|Select|Wrap|Line Numbers
- void main()
- {
- ifstream InFile("Myfile", ios::binary);
- unsigned char message[33];
- int bin[264];
- if (!InFile)
- {
- cerr<<"InFile could not be opened";
- exit(1);
- }
- InFile.read( (char *)message, 33);
- cout<<"my message is:";
- for ( int i =0; i< sizeof(message) ; i++)
- cout<<message[i];
- readByte(message, bin);
- cout<<"\n"<<"my binary representation is:";
- for ( int i =0; i< 264 ; i++)
- cout<<bin[i];
- }