M
Michal Wyrebski
Hello,
I was thinking how is the fastest and the best way of passing bitset
variable to some function.
Only one method came to my mind. It's about passing converted value:
#v+
void func(unsigned long UL) {
bitset<8> B(UL);
cout << "B: " << B << endl;
}
int main() {
bitset<8> H('A');
func(H.to_ulong() );
return 0;
}
#v-
Of course converting to string is also possible.
OK this just works. But what if I want to pass some number of bits and
func() had no information about its number?
It's impossible to write like that:
#v+
void func(unsigned long UL, const int len) {
bitset<len> B(UL);
(...)
#v-
g++ says: `len' cannot appear in a constant-expression
How, then, pass some number of bits, that function could create
stucture (bitset) of required length?
Any ideas?
Michal
I was thinking how is the fastest and the best way of passing bitset
variable to some function.
Only one method came to my mind. It's about passing converted value:
#v+
void func(unsigned long UL) {
bitset<8> B(UL);
cout << "B: " << B << endl;
}
int main() {
bitset<8> H('A');
func(H.to_ulong() );
return 0;
}
#v-
Of course converting to string is also possible.
OK this just works. But what if I want to pass some number of bits and
func() had no information about its number?
It's impossible to write like that:
#v+
void func(unsigned long UL, const int len) {
bitset<len> B(UL);
(...)
#v-
g++ says: `len' cannot appear in a constant-expression
How, then, pass some number of bits, that function could create
stucture (bitset) of required length?
Any ideas?
Michal