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 19 of file i2v32.c.

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

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 19 of file i2v64.c.

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

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 19 of file v2i32.c.

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

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 19 of file v2i64.c.

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


Generated on Tue Jun 19 20:38:44 2007 for lucid by  doxygen 1.5.2