* Copyright 2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Brecht Machiels, brecht@mos6581.org
*/
#ifndef _BINARY_UTILS_H
#define _BINARY_UTILS_H
*/
#define BIT(n) (1ULL << n)
*/
#define BITMASK(high, low) ((unsigned long long)(BitMask<high, low>::value))
template<int h, int l>
struct BitMask
{
enum { value = (BitMask<h-l-1,0>::value +
(1ULL << h - l)) << l };
};
template<>
struct BitMask<-1,0>
{
enum { value = 0ULL };
};
*/
#define BINARY(binstring) ((unsigned long long)(Binary<0##binstring>::value))
template<const unsigned long long N> struct Binary
{
enum { value = (N % 8ULL) + 2ULL * Binary<N / 8ULL>::value };
};
template<>
struct Binary<0>
{
enum { value = 0ULL } ;
};
NOTE: broken for high bit indices
*/
#define MASKOFFSET(mask) (MaskOffset<mask, (mask & 1UL)>::count)
template<const unsigned long mask, unsigned int firstBit>
struct MaskOffset
{
enum { count = MaskOffset<(mask >> 1), ((mask >> 1) & 1UL)>::count + 1 };
};
template<const unsigned long mask>
struct MaskOffset<mask, 1>
{
enum { count = 0 };
};
#endif