aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BigInt.c59
-rw-r--r--BigInt.h5
2 files changed, 64 insertions, 0 deletions
diff --git a/BigInt.c b/BigInt.c
index 4323443..a1a617c 100644
--- a/BigInt.c
+++ b/BigInt.c
@@ -248,6 +248,65 @@ B_sub(BigInt *inta, BigInt intb) {
}
Result
+B_compl(BigInt *intx) {
+ if (NULL == intx)
+ return R_NullArgument;
+
+ struct BigIntMeta *xm = B_metadata(intx);
+ UWord *x = (void*)intx;
+
+ for (usize i = 0; i < xm->words; ++i)
+ x[i] = ~x[i];
+
+ return R_Ok;
+}
+
+Result
+B_bitand(BigInt *intx, BigInt *inty) {
+ if (NULL == intx || NULL == inty)
+ return R_NullArgument;
+
+ struct BigIntMeta *xm = B_metadata(intx), *ym = B_metadata(inty);
+ UWord *x = (void*)intx, *y = (void*)inty;
+
+ usize size = xm->words < ym->words ? xm->words : ym->words;
+ for (usize i = 0; i < size; ++i)
+ x[i] &= y[i];
+
+ return R_Ok;
+}
+
+Result
+B_bitor(BigInt *intx, BigInt *inty) {
+ if (NULL == intx || NULL == inty)
+ return R_NullArgument;
+
+ struct BigIntMeta *xm = B_metadata(intx), *ym = B_metadata(inty);
+ UWord *x = (void*)intx, *y = (void*)inty;
+
+ usize size = xm->words < ym->words ? xm->words : ym->words;
+ for (usize i = 0; i < size; ++i)
+ x[i] |= y[i];
+
+ return R_Ok;
+}
+
+Result
+B_bitxor(BigInt *intx, BigInt *inty) {
+ if (NULL == intx || NULL == inty)
+ return R_NullArgument;
+
+ struct BigIntMeta *xm = B_metadata(intx), *ym = B_metadata(inty);
+ UWord *x = (void*)intx, *y = (void*)inty;
+
+ usize size = xm->words < ym->words ? xm->words : ym->words;
+ for (usize i = 0; i < size; ++i)
+ x[i] ^= y[i];
+
+ return R_Ok;
+}
+
+Result
B_rshift(BigInt *intx, usize shift) {
if (NULL == intx || NULL == *intx)
return R_NullArgument;
diff --git a/BigInt.h b/BigInt.h
index 913e249..d894b35 100644
--- a/BigInt.h
+++ b/BigInt.h
@@ -23,6 +23,11 @@ Result B_free(BigInt *bigint);
Result B_sum(BigInt *a, BigInt b);
Result B_sub(BigInt *a, BigInt b);
+
+Result B_compl(BigInt *x);
+Result B_bitand(BigInt *x, BigInt *y);
+Result B_bitor(BigInt *x, BigInt *y);
+Result B_bitxor(BigInt *x, BigInt *y);
Result B_rshift(BigInt *x, usize shift);
Result B_lshift(BigInt *x, usize shift);