MSB/LSB template
//////////////////////////////////////////////////////////////////
//
// MSB : most significant bit/byte
//
// bit : 최상위 비트
// byte : 최상위 바이트
//
// MSB<0>::bit == 0
// MSB<0>::byte == 0
// MSB<1>::bit == 1
// MSB<1>::byte == 1
// MSB<0x100>::bit == 9
// MSB<0x100>::byte == 2
// MSB<0x101>::bit == 9
// MSB<0x101>::byte == 2
// MSB<0x10000000>::bit == 32
// MSB<0x10000000>::byte == 4
// MSB<0x10000001>::bit == 32
// MSB<0x10000001>::byte == 4
//
//////////////////////////////////////////////////////////////////
template<DWORD N>
struct MSB
{
static unsigned const bit = MSB<(N>>1)>::bit + 1;
static unsigned const byte = MSB<(N>>8)>::byte + 1;
};
template<>
struct MSB<0>
{
static unsigned const bit = 0;
static unsigned const byte = 0;
};
//////////////////////////////////////////////////////////////////
//
// LSB : least significant bit/byte
//
// bit : 최하위 비트
// byte : 최하위 바이트
//
// LSB<0>::bit == 0
// LSB<0>::byte == 0
// LSB<1>::bit == 1
// LSB<1>::byte == 1
// LSB<0x100>::bit == 9
// LSB<0x100>::byte == 2
// LSB<0x101>::bit == 1
// LSB<0x101>::byte == 1
// LSB<0x10000000>::bit == 32
// LSB<0x10000000>::byte == 4
// LSB<0x10000001>::bit == 1
// LSB<0x10000001>::byte == 1
//
//////////////////////////////////////////////////////////////////
template<DWORD N>
struct LSB_temp
{
static unsigned const bit = LSB_temp<(N<<1)>::bit + 1;
static unsigned const byte = LSB_temp<(N<<8)>::byte + 1;
};
template<>
struct LSB_temp<0>
{
static unsigned const bit = 0;
static unsigned const byte = 0;
};
template<DWORD N>
struct LSB
{
static unsigned const bit = 33-LSB_temp<N>::bit;
static unsigned const byte = 5-LSB_temp<N>::byte;
};
template<>
struct LSB<0>
{
static unsigned const bit = 0;
static unsigned const byte = 0;
};