# bitmath_func.cpp File Reference

Functions related to bit mathematics. More...

`#include "../stdafx.h"`
`#include "bitmath_func.hpp"`

Go to the source code of this file.

## Functions

uint8 | FindFirstBit (uint32 x)
| Search the first set bit in a 32 bit variable.
uint8 | FindLastBit (uint64 x)
| Search the last set bit in a 64 bit variable.

## Variables

const uint8 | _ffb_64 [64]
| Lookup table to check which bit is set in a 6 bit variable.

## Detailed Description

Functions related to bit mathematics.

Definition in file bitmath_func.cpp.

## Function Documentation

uint8 FindFirstBit | ( | uint32 | x | ) |

Search the first set bit in a 32 bit variable.

This algorithm is a static implementation of a log conguence search algorithm. It checks the first half if there is a bit set search there further. And this way further. If no bit is set return 0.

Parameters:

  | x | The value to search

Returns:
  The position of the first bit set

Definition at line 37 of file bitmath_func.cpp.

Referenced by AllocateMap(), CalculateRefitMasks(), and ExploreSegment().

uint8 FindLastBit | ( | uint64 | x | ) |

Search the last set bit in a 64 bit variable.

This algorithm is a static implementation of a log conguence search algorithm. It checks the second half if there is a bit set search there further. And this way further. If no bit is set return 0.

Parameters:

  | x | The value to search

Returns:
  The position of the last bit set

Definition at line 65 of file bitmath_func.cpp.

Referenced by BaseGraphWindow::DrawGraph().

## Variable Documentation

const uint8 _ffb_64[64]

Initial value:

     {
      0,  0,  1,  0,  2,  0,  1,  0,
      3,  0,  1,  0,  2,  0,  1,  0,
      4,  0,  1,  0,  2,  0,  1,  0,
      3,  0,  1,  0,  2,  0,  1,  0,
      5,  0,  1,  0,  2,  0,  1,  0,
      3,  0,  1,  0,  2,  0,  1,  0,
      4,  0,  1,  0,  2,  0,  1,  0,
      3,  0,  1,  0,  2,  0,  1,  0,
    }

Lookup table to check which bit is set in a 6 bit variable.

Definition at line 15 of file bitmath_func.cpp.