#ifndef Fpc6
#define Fpc6
#include <string>
#include <fstream>
usingnamespace std;
class fpc6{
private:
//unsigned int fpc6Array[];
int fpc6_size;
public:
// default constructor, tracks number of fpc6 characters converted and the size of the packedfpc6 array
//Graeme Hart
fpc6() {
fpc6_size = 0;
}
// convert ascii char to unsigned int between 0 and 31
unsignedint asciiToFpc6(char c)
{
unsignedint x = 0;
if (c >= 97 && c <= 122){
x = c - 97;
} //a-z
if (c == 13){ x = 26; } //CR
if (c == 32){ x = 27; } //SPACE
if (c == 39){ x = 28; } //'
if (c == 46){ x = 29; } //.
if (c == 59){ x = 30; } //;
else{ x = 31; }
return x;
}
// convert unsigned int between 0 and 31 to ascii char
char fpc6ToAscii(unsignedint x)
{
char c = 'a';
if (x >= 0 && x <= 25){
c = x + 97;
} //a-z
if (x == 26){ c = 13; } //CR
if (x == 27){ c = 32; } //SPACE
if (x == 28){ c = 39; } //'
if (x == 29){ c = 46; } //.
if (x == 30){ c = 59; } //;
else{ c = 63; }
return c;
}
// accepts string with at least 6 ascii chars and returns a single unsigned
// containing the first 6 characters packed into a single unsigned int.
// If string length <6 then pad with spaces.
unsignedint pack6Fpc6IntoUnsigned(string s)
{
unsignedint x = 0;
int bitShifter = 25;
if (s.length() > 6)
return -1;
for (int i = 0; i < 6; i++){
if(i >= s.length()){
x | 27 << bitShifter;
}
else{
x | asciiToFpc6(s.at(i));
x << bitShifter;
bitShifter -= 5;
fpc6_size++;
}
}
return x;
}
//default destructor
~fpc6() {
fpc6_size = 0;
}
};
#endif
Additionally VS apparently doesn't like my bitwise operators in my class functions and doesn't think they're doing anything. It gives "warning C4552: ['|', '<<', '>>', '&'] : operator has no effect; expected operator with side-effect" for all of them, but it seems to me the code should work fine and actually accomplish things....
I only gave the relevant code because it makes it easier for you guys to parse whats going on, there are class-functions I haven't included on my post that need these ones to be there to work properly.
On line 10 of Source.cpp, remove the brackets: fpc6 t0(); --> fpc6 t0;
Additionally VS apparently doesn't like my bitwise operators in my class functions and doesn't think they're doing anything. It gives "warning C4552: ['|', '<<', '>>', '&'] : operator has no effect; expected operator with side-effect" for all of them, but it seems to me the code should work fine and actually accomplish things....
The operators | & << >> do not modify the operands directly (what I mean is: for x << y; x and y will not be modified, but rather operator<< will return the result). I think what you want to be doing is using the bitwise assignment operators (it's midnight and I have no idea if that's what they're called or not): |= &= <<= >>=.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
int main()
{
int x, y;
x = y = 10;
std::cout<< "["<< x<< ", "<< y<< "]\n";
x & 5;
y &= 5;
std::cout<< "["<< x<< ", "<< y<< "]\n";
x = y = 10;
x<< 5;
y<<= 5;
std::cout<< "["<< x<< ", "<< y<< "]\n";
}
[10, 10]
[10, 0]
[10, 320]
Notice how when the bitwise operators & and << are used, x remains the same, and when &= and <<= are used, y is changed.
I knew it was something simple and wonky. I don't recall Dev C++ being so picky about having empty parameters when declaring an object when I used to use it, but maybe it did too.
Also yes, bitwise assignment operators are what I wanted. Thanks!
The default constructor is the constructor that takes no parameters, and it is special because it is called when an object is declared but is not initialized with any arguments. In the example above, the default constructor is called for rectb. Note how rectb is not even constructed with an empty set of parentheses - in fact, empty parentheses cannot be used to call the default constructor:
1 2
Rectangle rectb; // ok, default constructor called
Rectangle rectc(); // oops, default constructor NOT called
This is because the empty set of parentheses would make of rectc a function declaration instead of an object declaration: It would be a function that takes no arguments and returns a value of type Rectangle.