From 32efae91eee62ef0e008a362eed05857a7a589bf Mon Sep 17 00:00:00 2001 From: mratsim Date: Fri, 16 Feb 2018 11:33:11 +0100 Subject: [PATCH] add basic logical operations --- src/mpint.nim | 2 ++ src/uint_bitwise_ops.nim | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/uint_bitwise_ops.nim diff --git a/src/mpint.nim b/src/mpint.nim index b44d556..7842cc2 100644 --- a/src/mpint.nim +++ b/src/mpint.nim @@ -3,8 +3,10 @@ import ./uint_type, ./uint_init, + ./uint_bitwise_ops, ./uint_binary_ops export uint_type, uint_init, + uint_bitwise_ops, uint_binary_ops \ No newline at end of file diff --git a/src/uint_bitwise_ops.nim b/src/uint_bitwise_ops.nim new file mode 100644 index 0000000..e51233f --- /dev/null +++ b/src/uint_bitwise_ops.nim @@ -0,0 +1,25 @@ +# Copyright (c) 2018 Status Research & Development GmbH +# Distributed under the MIT License (license terms are at http://opensource.org/licenses/MIT). + +import uint_type + + +proc `not`*(x: MpUint): MpUint {.noInit, noSideEffect, inline.}= + ## Bitwise complement of unsigned integer x + result.lo = not x.lo + result.hi = not x.hi + +proc `or`*(x, y: MpUint): MpUint {.noInit, noSideEffect, inline.}= + ## `Bitwise or` of numbers x and y + result.lo = x.lo or y.lo + result.hi = x.hi or y.hi + +proc `and`*(x, y: MpUint): MpUint {.noInit, noSideEffect, inline.}= + ## `Bitwise and` of numbers x and y + result.lo = x.lo and y.lo + result.hi = x.hi and y.hi + +proc `xor`*(x, y: MpUint): MpUint {.noInit, noSideEffect, inline.}= + ## `Bitwise xor` of numbers x and y + result.lo = x.lo xor y.lo + result.hi = x.hi xor y.hi \ No newline at end of file