I am trying to write a function that asks the user to input multiple hex strings to a console and then convert those strings to bitsets. I want the function to use pointers to the bitsets so that the bitsets are stored in the parent function. Due to not using c++ 11 I split the 64bit bitset into two hex conversion operations.
void consoleDataInput(bitset<1> verbose, bitset<32>* addr, bitset<64>* wdata, bitset<8>* wdata_mask, bitset<1>* rdnwr)
{
cout << "enter 1 for read 0 for write : ";
cin >> *rdnwr;
string tempStr;
unsigned long tempVal;
istringstream tempIss;
// Input the addr in hex and convert to a bitset
cout << "enter addr in hex : ";
cin >> tempStr;
tempIss.str(tempStr);
tempIss >> hex >> tempVal;
*addr = tempVal;
// enter wdata and wdata_mask in hex and convert to bitsets
if (rdnwr[0] == 1)
{
*wdata = 0;
*wdata_mask = 0;
}
else
{
// wdata
bitset<32> tempBitset;
cout << "enter wdata in hex : ";
cin >> tempStr;
if (tempStr.length() > 8)
{
tempIss.str(tempStr.substr(0,tempStr.length()-8));
tempIss >> hex >> tempVal;
tempBitset = tempVal;
for (int i=31; i>=0; i--)
{
wdata[i+32] = tempBitset[i];
}
tempIss.str(tempStr.substr(tempStr.length()-8,tempStr.length()));
tempIss >> hex >> tempVal;
tempBitset = tempVal;
for (int i=32; i>=0; i--)
{
wdata[i] = tempBitset[i];
}
}
else
{
tempIss.str(tempStr);
tempIss >> hex >> tempVal;
tempBitset = tempVal;
for (int i=32; i>=0; i--)
{
wdata[i] = tempBitset[i];
}
}
// wdata_mask
cout << "enter wdata_mask in hex : ";
cin >> tempStr;
tempIss.str(tempStr);
tempIss >> hex >> tempVal;
*wdata_mask = tempVal;
}
When I try to compile using GCC in code::blocks I get the error
C:\Diolan\DLN\demo\ApolloSPI\main.cpp|202|error: no match for 'operator=' in '*(wdata + ((((sizetype)i) + 32u) * 8u)) = std::bitset<_Nb>::operator[](std::size_t) [with unsigned int _Nb = 32u; std::size_t = unsigned int](((std::size_t)i))'|
Which is highlighting the line
wdata[i+32] = tempBitset[i];
As I understand it, I don't need to use the * operator before wdata[i+32]
because the [i+32]
acts as the indication that it is a pointer.
I am unsure how to move forward. The =
operator is a valid one to use with a bitset so I don't understand the error.
Thanks.