Exchanging byte sizes

Hey I have an advanced data namespace in which I hope to be able to read a data variable of any type and transfer it's bytes into another type of a multiple size.

i.e.
char[4] -> int;
int -> short[2];
short -> char[2];
char[2] -> short;

but I'm having some trouble, I get the following errors (because as a template it must compile from start)

error C2296: '&=' : illegal, left operand has type 'double'
error C2296: '&=' : illegal, left operand has type 'float'
error C2297: '&=' : illegal, left operand has type 'double'
error C2297: '&=' : illegal, left operand has type 'float'


This is the problem template (UCHAR is a typedef of "unsigned char" btw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
template<typename T1, typename T2> void stepBytes(UCHAR size1, UCHAR size2, T1 in, T2& out){
	if(size1 == 0 || size2 == 0)
		return;
	if(size1 % size2 != 0 &&
		size2 % size1 != 0)
		return;
	
	int mult = ceil(size2/size1);
	char** temp = new char[mult][size1];
	for(int i=0; i<mult; i++){
		for(int j=0; j<size1; j++){
			temp[i][j] = (char)((in[i] >> j) & 0xFF);
		}
	}
	int count = 0;
	out = (T2)NULL;
	for(int i=0; i<mult; i++){
		for(int j=0; j<size2; j++){
			out &= (T2)(temp[i][j] << count);        //All errors show this line
			count++;
		}
	}
	delete temp;
}


So, why's this error appearing?
Last edited on
Purely from the error text, it looks like you are trying to realize this function with the type T2 equal to float or double, which makes like 19 illegal as you can't apply bitwise operators to floats or doubles.
Oh right, I didn't know that bitwise operators couldn't be used with floating types, :(
Well I do have a backup plan so I suppose I'll just have to scrap this idea and go back to the fscanf_s(...); or the string equivalent.
Topic archived. No new replies allowed.