mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-04-20 06:16:43 +00:00
Couple of small refactorings, based on repeated bit patterns
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
+12
-8
@@ -12,6 +12,10 @@ namespace EightBit
|
||||
{
|
||||
}
|
||||
|
||||
public static byte Bit(int which) => (byte)(1 << which);
|
||||
|
||||
public static byte Bit(byte which) => Bit((int)which);
|
||||
|
||||
public static byte SetBit(byte input, byte which) => (byte)(input | which);
|
||||
|
||||
public static byte SetBit(byte input, byte which, int condition) => SetBit(input, which, condition != 0);
|
||||
@@ -72,22 +76,22 @@ namespace EightBit
|
||||
|
||||
public static bool EvenParity(byte value) => EvenParity((int)value);
|
||||
|
||||
public static int FindFirstSet(int x)
|
||||
public static int FindFirstSet(int value)
|
||||
{
|
||||
if (x == 0)
|
||||
if (value == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var t = 1;
|
||||
var r = 1;
|
||||
while ((x & t) == 0)
|
||||
var test = 1;
|
||||
var result = 1;
|
||||
while ((value & test) == 0)
|
||||
{
|
||||
t <<= 1;
|
||||
++r;
|
||||
test <<= 1;
|
||||
++result;
|
||||
}
|
||||
|
||||
return r;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user