It locates the first bit in a byte that's set to a '1'
Code: Select all
//
// find lowest bit set in a byte
// returns bitmask indicating the first set bit, or 0 if none are set
//
function FindLowestBit(b as byte) as byte
// this function computes 'result = b and -b'
// however, the expression 'b and -b' will use 16-bit math by default
// this assignment will allow the compiler to use bytes instead
dim bb as byte = -b
result = b and bb
end function
Code: Select all
function FindLowestBit(w as word) as word
// use words instead of longwords
dim ww as word = -w
result = w and ww
end function
Code: Select all
y = FindLowestBit(not(x))