Bitmap conversion


Detailed Description

The i2v and v2i family of functions convert between a bitmap and a bit index.

A bitmap is simply an integer with certain bits being 1 (enabled) and 0 (disabled).

These functions only return usable results if exactly one bit is enabled.

These functions are mainly used by the flist family of functions.


Functions

uint32_t i2v32 (int index)
 convert bit index to 32 bit value
uint64_t i2v64 (int index)
 convert bit index to 64 bit value
int v2i32 (uint32_t val)
 convert 32 bit value to bit index
int v2i64 (uint64_t val)
 convert 64 bit value to bit index


Function Documentation

uint32_t i2v32 ( int  index  ) 

convert bit index to 32 bit value

Parameters:
[in] index bit index (0-31)
Returns:
32 bit value

Definition at line 20 of file i2v32.c.

00021 {
00022         if (index < 0 || index > 31)
00023                 return 0;
00024         
00025         return (1UL << index);
00026 }

uint64_t i2v64 ( int  index  ) 

convert bit index to 64 bit value

Parameters:
[in] index bit index (0-63)
Returns:
64 bit value

Definition at line 20 of file i2v64.c.

00021 {
00022         if (index < 0 || index > 63)
00023                 return 0;
00024         
00025         return (1ULL << index);
00026 }

int v2i32 ( uint32_t  val  ) 

convert 32 bit value to bit index

Parameters:
[in] val 32 bit value
Returns:
bit index (0-31)

Definition at line 20 of file v2i32.c.

00021 {
00022         int index = 0;
00023         
00024         if (val == 0)
00025                 return -1;
00026         
00027         while ((val = val >> 1))
00028                 index++;
00029         
00030         return index;
00031 }

int v2i64 ( uint64_t  val  ) 

convert 64 bit value to bit index

Parameters:
[in] val 64 bit value
Returns:
bit index (0-63)

Definition at line 20 of file v2i64.c.

00021 {
00022         int index = 0;
00023         
00024         if (val == 0)
00025                 return -1;
00026         
00027         while ((val = val >> 1))
00028                 index++;
00029         
00030         return index;
00031 }


Generated on Sun Dec 3 17:46:16 2006 for lucid by  doxygen 1.5.1