tor  0.4.2.0-alpha-dev
Functions
bits.c File Reference
#include "lib/intmath/bits.h"

Go to the source code of this file.

Functions

int tor_log2 (uint64_t u64)
 
uint64_t round_to_power_of_2 (uint64_t u64)
 
int n_bits_set_u8 (uint8_t v)
 

Detailed Description

Count the bits in an integer, manipulate powers of 2, etc.

Definition in file bits.c.

Function Documentation

◆ n_bits_set_u8()

int n_bits_set_u8 ( uint8_t  v)

Return the number of bits set in v.

Definition at line 72 of file bits.c.

◆ round_to_power_of_2()

uint64_t round_to_power_of_2 ( uint64_t  u64)

Return the power of 2 in range [1,UINT64_MAX] closest to u64. If there are two powers of 2 equally close, round down.

Definition at line 49 of file bits.c.

References tor_log2().

◆ tor_log2()

int tor_log2 ( uint64_t  u64)

Returns floor(log2(u64)). If u64 is 0, (incorrectly) returns 0.

Definition at line 16 of file bits.c.

Referenced by domain_to_string(), and round_to_power_of_2().