1)Then I ran the code below, is there some reason you cannot type cast into a vector?
1 2 3 4 5 6
|
vector<char>values;
for( int i =0; i<size ; ++i )
{
values.push_back(static_cast<double>( memblock[i] ) );
}
| |
You can't insert a double into a vector of chars.
2) I am having a logical error with my bin2dec conversion, because my .bin file does not have the asci characters '0'&'1' might someone have a solution to that?
have you tried comparing the values against 0 and 1 rather than '0' and '1'. As you say, the file doesn't have the ascii characters representing 0 and 1, but rather they have 0 and one directly.
However, there might be other problems, because you are reading them one char at a time. a char is typically an 8 bit data type, and if your binary file is tightly packed, then you will have to add a loop of some kind similar to this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int bin2dec(const char *bin)
{
int result=0;
for(;*bin;bin++)
{
int mask = 1;
for(int i = 0; i < size(*bin), t++){
result = result << 1;
result = result + (*bin&mask);
mast = mask << 1;
}
return result;
}
| |
_<<_ is a bitwise shift operator
_&_ is a bitwise and.
I haven't tested it, so it may not be exactly right.