0% found this document useful (0 votes)
31 views

C Reference Manual - October 2005.105

Tests the specified bit (0-7,0-15 or 0-31) in a given variable and returns a non-zero value if the bit is set to 1. It is more efficient than using bitwise AND and comparing to 1, shifted by the bit position. The function works on all devices and no other functions are required. Example usage includes checking individual bits in a variable or finding the most significant bit set to 1.

Uploaded by

diegoifg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

C Reference Manual - October 2005.105

Tests the specified bit (0-7,0-15 or 0-31) in a given variable and returns a non-zero value if the bit is set to 1. It is more efficient than using bitwise AND and comparing to 1, shifted by the bit position. The function works on all devices and no other functions are required. Example usage includes checking individual bits in a variable or finding the most significant bit set to 1.

Uploaded by

diegoifg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Built-In Functions

Function:

Tests the specified bit (0-7,0-15 or 0-31) in the given


variable. The least significant bit is 0. This function is
much more efficient than, but otherwise the same as: ((var &
(1<<bit)) != 0)

Availability:

All devices

Requires

Nothing

Examples:

if( bit_test(x,3) || !bit_test (x,1) ){


//either bit 3 is 1 or bit 1 is 0
}

if(data!=0)
for(i=31;!bit_test(data, i);i--) ;
// i now has the most significant bit in data
// that is set to a 1

Example Files:

ex_patg.c

Also See:

bit_clear(), bit_set()

BSEARCH()
Syntax:

ip = bsearch (&key, base, num, width, compare)

Parameters:

key: Object to search for


base: Pointer to array of search data
num: Number of elements in search data
width: Width of elements in search data
compare: Function that compares two elements in search
data

Returns:

bsearch returns a pointer to an occurrence of key in the array


pointed to by base. If key is not found, the function returns
NULL. If the array is not in order or contains duplicate records
with identical keys, the result is unpredictable.

Function:

Performs a binary search of a sorted array

Availability:

All devices

93

You might also like