Link to home
Start Free TrialLog in
Avatar of kk8
kk8

asked on

template related question

Hi,
How do you generalize this module to work for any integer value instead of 2?

std::string ToBinString(unsigned long val, int ndigits ){      
      const std::bitset<2> bs(val); //Generalize this - use any integer instead of 2
      const std::string s(bs.to_string());
      return s;
}

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of trinitrotoluene
trinitrotoluene
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kk8
kk8

ASKER

Thanks for the code. I think you meant

template <size_t T>

instead of

template <class T>

Did not realize i could use size_t as a template, silly me.