Hi I have been trying to get the following function using bitset structures to work for a while now but I cant seem to get around the segmentation fault. Can anyone point out where I'm going wrong with this:
class bitset_class {
public:
ob binread;
void set_bits();
void conversion(unsigned short int*, int);
};
void bitset_class::set_bits(){
for(int i=0; i<MAXBITCOUNT; i++)
binread.bo.set(i,0);
}
void bitset_class::conversion(unsigned short int* single_read, int seq_length){
int i, j;
bitset<3> temp;
You cannot, under most circumstances, including yours, use malloc() for classes. malloc() does not run
constructors, and therefore you bitset_class instance is being used uninitialized.
I would also appreciate it if you could tell me a simpler method to accomplish this, i.e, convert a 2 dimensional array of integers ranging from 0 to 4 and store them as a series of binary words.
I don't know if n (in main) is constant or not. If it is constant, then you can simply allocate an array of bitsets on
the stack, otherwise use new:
1 2
// Runs default constructor of bitset_class() for each of the n instances created
bitset_class* bin_reads = new bitset_class[ n ];
I need to know what the parameters to conversion() are supposed to be. Is seq_length supposed to be
the number of bytes to convert, the number of unsigned shorts to convert (guessing that short == 2 bytes),
or the number of bits?
I just tried with this initialization and I am still getting a segmentation fault.
n in the main is a constant.
seq_length is just the size of the r[i] array, i.e, above r[i] is an array of 53 unsigned short ints and r is a 2 dimensional array with n rows of seq_length unsigned short int arrays.
So then is conversion supposed to take all the bits from 53 unsigned shorts (53*16 is over 800 bits) and stuff
them into a bitset<> that contains only 210 bits? Or what is conversion supposed to do?
The idea is to convert a series of numbers (stored in r) ranging from 0 to 4 into a bitset that stores all the numbers in their binary form in a single binary word.