Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Bits.cs
Go to the documentation of this file.
1namespace System.Xml;
2
3internal static class Bits
4{
5 public static int Count(uint num)
6 {
7 num = (num & 0x55555555) + ((num >> 1) & 0x55555555);
8 num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
9 num = (num & 0xF0F0F0F) + ((num >> 4) & 0xF0F0F0F);
10 num = (num & 0xFF00FF) + ((num >> 8) & 0xFF00FF);
11 num = (num & 0xFFFF) + (num >> 16);
12 return (int)num;
13 }
14
15 public static bool ExactlyOne(uint num)
16 {
17 if (num != 0)
18 {
19 return (num & (num - 1)) == 0;
20 }
21 return false;
22 }
23
24 public static uint ClearLeast(uint num)
25 {
26 return num & (num - 1);
27 }
28
29 public static int LeastPosition(uint num)
30 {
31 if (num == 0)
32 {
33 return 0;
34 }
35 return Count(num ^ (num - 1));
36 }
37}
static bool ExactlyOne(uint num)
Definition Bits.cs:15
static int LeastPosition(uint num)
Definition Bits.cs:29
static uint ClearLeast(uint num)
Definition Bits.cs:24
static int Count(uint num)
Definition Bits.cs:5