So I have been working on this code where I have to partition 8 bits into two set of 4 bits each.So far I have been trying my luck with bitset<> container class in C++.But it doesnt give me any ability copy first 4 bits of bitset<8> to first bitset<4> and remaining four bits to another one...
Here is the code that I have written so far...I want to convert a character to 8 bits and the divides these 8 bits into two sets of 4 bits each.
This thing displays only the correct values of LHS and all values of RHS as 0000.How do I get the correct values of RHS bitset<4>?
Kindly help.
Thanks in advance.
Here is the code that I have written so far...I want to convert a character to 8 bits and the divides these 8 bits into two sets of 4 bits each.
Code:
FILE * fil;
fil = fopen("test", "r");
do {
ch = fgetc(fil);
str[counter++] = ch;
} while (ch != EOF);
fclose(fil);
struct binary {
bitset < 8 > bitval;
char chr;
bitset < 4 > lhs;
bitset < 4 > rhs;
} bin[counter];
for (i = 0; i < counter; i++) {
bin[i].bitval = str[i];
bin[i].chr = str[i];
}
for (i = 0; i < counter; i++) {
cout << bin[i].chr << " " << bin[i].bitval<< endl;
}
for (i = 0; i < counter; i++) {
for(j=0;j<4;j++)
{
bin[i].lhs[j]=bin[i].bitval[j];
}
}
for (i = 0; i < counter; i++) {
for(j=4;j < 8;j++)
{
bin[i].rhs[j]=bin[i].bitval[j];
}
}
Kindly help.
Thanks in advance.
Comment