-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBI_BitwiseOps.c
More file actions
31 lines (25 loc) · 1.01 KB
/
BI_BitwiseOps.c
File metadata and controls
31 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "BI_Structure.h"
BigInteger BI_Shr(BigInteger bi, int shift) {
if (shift == 0) return bi;
if (shift >= 64) return BI_Create(0, bi.MSBs >> (shift - 64));
if (shift >= 128) return BI_Create(0, 0);
return BI_Create(bi.MSBs >> shift, (bi.LSBs >> shift) | ((bi.MSBs & ((1 << (shift - 1)) - 1)) << shift));
}
BigInteger BI_Shl(BigInteger bi, int shift) {
if (shift == 0) return bi;
if (shift >= 64) return BI_Create(bi.LSBs << (shift - 64), 0);
if (shift >= 128) return BI_Create(0, 0);
return BI_Create(bi.MSBs << shift | ((bi.LSBs >> (64 - shift)) & ((1 << (shift)) - 1)), bi.LSBs << shift);
}
BigInteger BI_Not(BigInteger bi) {
return BI_Create(~bi.MSBs, ~bi.LSBs);
}
BigInteger BI_Or(BigInteger bi1, BigInteger bi2) {
return BI_Create(bi1.MSBs | bi2.MSBs, bi1.LSBs | bi2.LSBs);
}
BigInteger BI_And(BigInteger bi1, BigInteger bi2) {
return BI_Create(bi1.MSBs & bi2.MSBs, bi1.LSBs & bi2.LSBs);
}
BigInteger BI_Xor(BigInteger bi1, BigInteger bi2) {
return BI_Create(bi1.MSBs ^ bi2.MSBs, bi1.LSBs ^ bi2.LSBs);
}