Class UIntBig


  • public class UIntBig
    extends java.lang.Object
    Mutable unsigned integer of unlimited size (for 32-bit architectures)
    • Constructor Summary

      Constructors 
      Constructor Description
      UIntBig()
      Zero
      UIntBig​(int bitLength, RandomSource random)  
      UIntBig​(long uint64)
      UInt64 value as unlimited value
      UIntBig​(short[] magnitude)
      From raw data
      UIntBig​(java.lang.String hexEncodedString)
      Hex encoded string with format MSB...LSB
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int bitLength()
      Count of bits based on highest set bit
      protected static int compare​(short[] a, short[] b)
      Compare a and b, ignoring leading zeros.
      protected int compare​(UIntBig value)
      Compare self with given value.
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      java.lang.String hexEncodedString()  
      protected boolean isOdd()
      Test if value is odd
      protected boolean isOne()
      Test if value is one
      protected boolean isZero()
      Test if value is zero
      short[] magnitude()  
      int minus​(UIntBig value, short multiplier, int offset)
      Replace self with self - value * multiplier (at offset of self).
      protected static void mod​(short[] a, short[] b)
      Modular function : b % a
      protected void mod​(UIntBig modulus)
      Replace self with self % modulus
      UIntBig modPow​(UIntBig exponent, UIntBig modulus)
      Modular exponentiation r = (a ^ b) % c where a=self, b=exponent, c=modulus.
      protected static void reduce​(short[] a, short[] b, int offset)
      Reduce b until b < a at offset by repeatedly deducting a from b at offset.
      protected void rightShiftByOne()
      Right shift all bits by one bit and insert leading 0 bit.
      protected static int subtract​(short[] a, short multiplier, short[] b, int offset)
      Subtraction function : b - a * multiplier (at offset of b)
      void times​(UIntBig multiplier)
      Replace self with self * multiplier.
      protected static short[] trimZeroMSBs​(short[] magnitude)
      Remove leading zeros from array
      long uint64()
      Get unsigned long value
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UIntBig

        public UIntBig​(@NonNull
                       short[] magnitude)
        From raw data
        Parameters:
        magnitude -
      • UIntBig

        public UIntBig()
        Zero
      • UIntBig

        public UIntBig​(long uint64)
        UInt64 value as unlimited value
        Parameters:
        uint64 -
      • UIntBig

        public UIntBig​(@NonNull
                       java.lang.String hexEncodedString)
        Hex encoded string with format MSB...LSB
        Parameters:
        hexEncodedString -
      • UIntBig

        public UIntBig​(int bitLength,
                       @NonNull
                       RandomSource random)
    • Method Detail

      • hexEncodedString

        @NonNull
        public java.lang.String hexEncodedString()
      • magnitude

        @NonNull
        public short[] magnitude()
      • uint64

        public long uint64()
        Get unsigned long value
        Returns:
      • isZero

        protected boolean isZero()
        Test if value is zero
        Returns:
      • isOne

        protected boolean isOne()
        Test if value is one
      • isOdd

        protected boolean isOdd()
        Test if value is odd
      • modPow

        @NonNull
        public UIntBig modPow​(@NonNull
                              UIntBig exponent,
                              @NonNull
                              UIntBig modulus)
        Modular exponentiation r = (a ^ b) % c where a=self, b=exponent, c=modulus. Performance test shows software implementation is acceptably slower than native hardware
        • Test samples = 399,626,333
        • Native 64-bit hardware = 416ns/call
        • Software 32-bit implementation = 3613ns/call
        Parameters:
        exponent - (b)
        modulus - (c)
        Returns:
        r, the result
      • mod

        protected void mod​(@NonNull
                           UIntBig modulus)
        Replace self with self % modulus
        Parameters:
        modulus -
      • reduce

        protected static final void reduce​(@NonNull
                                           short[] a,
                                           @NonNull
                                           short[] b,
                                           @NonNull
                                           int offset)
        Reduce b until b < a at offset by repeatedly deducting a from b at offset. Assumes b.length >= a.length + offset.
        Parameters:
        a -
        b -
        offset -
      • mod

        protected static final void mod​(@NonNull
                                        short[] a,
                                        @NonNull
                                        short[] b)
        Modular function : b % a
      • compare

        protected static final int compare​(@NonNull
                                           short[] a,
                                           @NonNull
                                           short[] b)
        Compare a and b, ignoring leading zeros.
        Parameters:
        a -
        b -
        Returns:
        -1 for a < b, 0 for a == b, 1 for a > b
      • compare

        protected int compare​(@NonNull
                              UIntBig value)
        Compare self with given value.
        Parameters:
        value -
        Returns:
        -1 for self < value, 0 for self == value, 1 for self > value
      • subtract

        protected static final int subtract​(@NonNull
                                            short[] a,
                                            short multiplier,
                                            @NonNull
                                            short[] b,
                                            int offset)
        Subtraction function : b - a * multiplier (at offset of b)
        Parameters:
        a -
        multiplier - , range [0,32767]
        b -
        offset -
        Returns:
      • minus

        public int minus​(@NonNull
                         UIntBig value,
                         short multiplier,
                         int offset)
        Replace self with self - value * multiplier (at offset of self).
        Parameters:
        value -
        multiplier - , range is [0,32767]
        offset -
        Returns:
      • times

        public void times​(@NonNull
                          UIntBig multiplier)
        Replace self with self * multiplier.
        Parameters:
        multiplier -
      • rightShiftByOne

        protected void rightShiftByOne()
        Right shift all bits by one bit and insert leading 0 bit.
      • trimZeroMSBs

        @NonNull
        protected static final short[] trimZeroMSBs​(@NonNull
                                                    short[] magnitude)
        Remove leading zeros from array
        Parameters:
        magnitude -
        Returns:
      • bitLength

        public int bitLength()
        Count of bits based on highest set bit
        Returns:
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object