Lunchbox  1.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Bit Operations.

Example: More...

Functions

template<class T >
int32_t lunchbox::getIndexOfLastBit (T value)
 
template<class T >
void lunchbox::byteswap (T &value)
 Swap the byte order of the given value. More...
 

Detailed Description

Example:

/* Copyright (c) 2011-2012, Stefan Eilemann <eile@eyescale.ch>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <test.h>
#include <lunchbox/bitOperation.h>
int main( int, char** )
{
TESTINFO( lunchbox::getIndexOfLastBit( 0u ) == -1,
TESTINFO( lunchbox::getIndexOfLastBit( 42u ) == 5,
TESTINFO( lunchbox::getIndexOfLastBit( LB_BIT12 ) == 11,
TESTINFO( lunchbox::getIndexOfLastBit( LB_BIT48 ) == 47,
uint16_t twoByte = 1;
lunchbox::byteswap( twoByte );
TESTINFO( twoByte == LB_BIT9, twoByte );
uint32_t fourByte = 1;
lunchbox::byteswap( fourByte );
TESTINFO( fourByte == LB_BIT25, fourByte );
uint64_t eightByte = 1;
lunchbox::byteswap( eightByte );
TESTINFO( eightByte == LB_BIT57, eightByte );
return EXIT_SUCCESS;
}

Function Documentation

template<class T >
void lunchbox::byteswap ( T &  value)

Swap the byte order of the given value.

Version
1.5.1
template<class T >
int32_t lunchbox::getIndexOfLastBit ( value)
Returns
the position of the last (most significant) set bit, or -1.
Version
1.8

Referenced by lunchbox::LFVector< T, nSlots >::LFVector(), and lunchbox::LFVector< T, nSlots >::operator[]().

+ Here is the caller graph for this function: