Help on Biset

Gokhan Kisacikoglu kisa@centropolisfx.com
Wed Nov 20 15:03:00 GMT 2002


Would this work until the functionality is established in the sgi
headers?

#include <iostream>
#include <bitset>

using namespace std;

template <size_t _Nb, class _WordT>
string &operator << (string &_s, bitset <_Nb, _WordT> _b)
{
  _s.assign(_Nb, '0');
  
  for (size_t i = 0; i < _Nb; ++i) 
    if (_b.test(i)) _s[_Nb - 1 - i] = '1';
  
  return _s;
}

template <size_t _Nb, class _WordT>
ostream &operator << (ostream &_s, bitset <_Nb, _WordT> _b)
{
  string s;
  s << _b;
  
  _s << s;
  return _s;
}

int
main(void)
{
    bitset <12> b( 96 );
    
    string s;
    s << b;
    
    cerr << s << " " << b << endl;
}



More information about the Gcc-help mailing list