yes, well im sorry if you don't understand this code, but skyhawk133 is extremely right, if you don't explain your problem in detail, you wont get the exact help you require;
i hope the following code helps, i've excessively added comments to help even beginners to c++;
CODE
#include <iostream>
using namespace std;
int main ()
{
//buffer = 00000000;
//any 0 before a binary sequence will cancel itself out;
//therefore buffer is really equal to 0;
//in this case, i've kept the number of bits in the sequence constant to one byte;
//a byte is approximately 8 bits;
//buffer = 0;
int nBuffer = 0x00;
//sequence = 0x06 which is really equal to 0110, but the leading 0 cancels out, so this becomes 110;
int nSequence = 0x06;
//buffer, which is equal to 0, gets assigned, 0 XOR 0x06, which is really;
// 00000000;
//^00000110;
//=00000110;
//if you don't understand the XOR (^) operator, you can find information about it by looking it up in google;
nBuffer = nBuffer ^ nSequence;
//we will let c++ output the result in decimal;
//output, nBuffer which is equal to nBuffer = nBuffer ^ nSequence; which equals 00000110;
cout << nBuffer << "\t: Buffer == 00000110;" << endl;
//shift the sequence 4 bits to the left, c++ will call in 4 trailing bits set to 0;
nBuffer = nBuffer << 4;
//buffer (00000110) = buffer (00000110) << 4 (01100000);
//output the new result in nBuffer;
//which is the return value of the top equation;
//(nBuffer = nBuffer << 4;);
cout << nBuffer << "\t: Buffer == 01100000;" << endl;
//now, we wanted to concatenate (add to the end of) 0010 to our value;
//so after we have shifted the value enough bits to the left, (exactly enough to fit in the new value),
//we can XOR our current nBuffer with the new value;
//01100000 = 01100000 ^ 00000010;
//which is in turn 01100010;
nBuffer = nBuffer ^ 0x02;
cout << nBuffer << "\t: Buffer == 01100010;" << endl;
cout << endl;
system ("PAUSE");
return 0;
}
this example was created by me in visual c++ 2005 professional!
This post has been edited by violent_crimson: 31 Aug, 2006 - 10:22 PM