00001 // Copyright 2006 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the 00015 // Free Software Foundation, Inc., 00016 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 /*! 00019 * @defgroup bitmap Bitmap conversion 00020 * 00021 * The i2v and v2i family of functions convert between a bitmap and a bit index. 00022 * 00023 * A bitmap is simply an integer with certain bits being 1 (enabled) and 0 00024 * (disabled). 00025 * 00026 * These functions only return usable results if exactly one bit is enabled. 00027 * 00028 * - Bit index to bitmap<br> 00029 * The resulting bitmask is a simple arithmetic left shift of 1 index times. 00030 * - Bitmap to bit index<br> 00031 * The resulting bit index is asimple arithmetic right shift until the map is 00032 * empty. 00033 * 00034 * These functions are mainly used by the flist family of functions. 00035 * 00036 * @{ 00037 */ 00038 00039 #ifndef _LUCID_BITMAP_H 00040 #define _LUCID_BITMAP_H 00041 00042 #include <stdint.h> 00043 00044 /*! 00045 * @brief convert bit index to 32 bit value 00046 * 00047 * @param[in] index bit index (0-31) 00048 * 00049 * @return 32 bit value 00050 */ 00051 uint32_t i2v32(int index); 00052 00053 /*! 00054 * @brief convert bit index to 64 bit value 00055 * 00056 * @param[in] index bit index (0-63) 00057 * 00058 * @return 64 bit value 00059 */ 00060 uint64_t i2v64(int index); 00061 00062 /*! 00063 * @brief convert 32 bit value to bit index 00064 * 00065 * @param[in] val 32 bit value 00066 * 00067 * @return bit index (0-31) 00068 */ 00069 int v2i32(uint32_t val); 00070 00071 /*! 00072 * @brief convert 64 bit value to bit index 00073 * 00074 * @param[in] val 64 bit value 00075 * 00076 * @return bit index (0-63) 00077 */ 00078 int v2i64(uint64_t val); 00079 00080 #endif 00081 00082 /*! @} bitmap */