Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as C++ by ProstoTyoma ( 14 years ago )
#ifndef BINARYCONV_HPP_
#define BINARYCONV_HPP_

//===========================================================
template<long long num>
class MetaIsOctal
{
public:
 enum { result = ((num < 10) && (num != 1) && (num != 0)) ? true : 
              (((num % 10) != 0) && ((num % 10) != 1)) || MetaIsOctal <num/10>::result };
};
//------------------------------------------------------------
template <>
class MetaIsOctal<0>
{
public:
 enum { result = false };
};
//------------------------------------------------------------
template <>
class MetaIsOctal<1>
{
public:
 enum { result = false };
};
//------------ ----------------- ---------------- -----------
template<long long num>
class MetaBinaryConverter
{
public:
 enum { result = MetaIsOctal<num>::result ? 
              ((num %  8) + 2 * MetaBinaryConverter<num/ 8>::result) :
              ((num % 10) + 2 * MetaBinaryConverter<num/10>::result) };
};
//------------------------------------------------------------
template <>
class MetaBinaryConverter <0>
{
public:
 enum { result = 0 };
};
//------------------------------------------------------------
template <>
class MetaBinaryConverter <1>
{
public:
 enum { result = 1 };
};

//===========================================================

#define BINARY(x) MetaBinaryConverter<x>::result
#define BINARY2(x,y) ((BINARY(x) << 8) + BINARY(y))
#define BN2MASK(x) (1 << (x))

#define BIT_TST(x,y) ((BN2MASK(y) & x) ? 1 : 0)
#define BIT_SET(x,y) (x = x | BN2MASK(y))
#define BIT_CLR(x,y) (x = x & ~BN2MASK(y))

//===========================================================


#endif /*BINARYCONV_HPP_*/

 

Revise this Paste

Your Name: Code Language: