mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-03-25 10:31:21 +00:00
Add a FindFirstSet implementation to the Chip class.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
853b6e2b08
commit
b4c37ea006
@ -4,6 +4,8 @@
|
||||
|
||||
namespace EightBit
|
||||
{
|
||||
using System.Collections.Specialized;
|
||||
|
||||
public class Chip : Device
|
||||
{
|
||||
protected Chip()
|
||||
@ -69,5 +71,19 @@ namespace EightBit
|
||||
public static bool EvenParity(int value) => CountBits(value) % 2 == 0;
|
||||
|
||||
public static bool EvenParity(byte value) => EvenParity((int)value);
|
||||
|
||||
public static int FindFirstSet(int value)
|
||||
{
|
||||
var bits = new BitVector32(value);
|
||||
for (var i = 31; i >= 0; --i)
|
||||
{
|
||||
if (bits[i])
|
||||
{
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user