java.lang.Object
org.mozilla.jss.netscape.security.util.BigInt
All Implemented Interfaces:
Serializable

public final class BigInt extends Object implements Serializable
A low-overhead arbitrary-precision unsigned integer. This is intended for use with ASN.1 parsing, and printing of such parsed values. Convert to "BigInteger" if you need to do arbitrary precision arithmetic, rather than just represent the number as a wrapped array of bytes.

NOTE: This class may eventually disappear, to be supplanted by big-endian byte arrays which hold both signed and unsigned arbitrary-precision integers.

Version:
1.23
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
     
    private byte[]
     
    private static final long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    BigInt(byte[] data)
    Constructs a "Big" integer from a set of (big-endian) bytes.
    BigInt(int i)
    Constructs a "Big" integer from a normal Java integer.
    Constructs a "Big" integer from a "BigInteger", which must be positive (or zero) in value.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the length of the data as a byte array.
    boolean
    equals(Object other)
    Returns true iff the parameter is a numerically equivalent BigInt.
    boolean
    equals(BigInt other)
    Returns true iff the parameter is numerically equivalent.
    int
     
    private String
     
    Returns a BigInteger value which supports many arithmetic operations.
    byte[]
    Returns the data as a byte array.
    int
    Converts the "big" integer to a java primitive integer.
    Returns a hexadecimal printed representation.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • BigInt

      public BigInt(byte[] data)
      Constructs a "Big" integer from a set of (big-endian) bytes. Leading zeroes should be stripped off.
      Parameters:
      data - a sequence of bytes, most significant bytes/digits first. CONSUMED.
    • BigInt

      public BigInt(BigInteger i)
      Constructs a "Big" integer from a "BigInteger", which must be positive (or zero) in value.
    • BigInt

      public BigInt(int i)
      Constructs a "Big" integer from a normal Java integer.
      Parameters:
      i - the java primitive integer
  • Method Details

    • toInt

      public int toInt()
      Converts the "big" integer to a java primitive integer.
      Throws:
      NumberFormatException - if 32 bits is insufficient.
    • toString

      public String toString()
      Returns a hexadecimal printed representation. The value is formatted to fit on lines of at least 75 characters, with embedded newlines. Words are separated for readability, with eight words (32 bytes) per line.
      Overrides:
      toString in class Object
    • toBigInteger

      public BigInteger toBigInteger()
      Returns a BigInteger value which supports many arithmetic operations. Assumes negative values will never occur.
    • byteLength

      public int byteLength()
      Returns the length of the data as a byte array.
    • toByteArray

      public byte[] toByteArray()
      Returns the data as a byte array. The most significant bit of the array is bit zero (as in java.math.BigInteger).
    • hexify

      private String hexify()
    • equals

      public boolean equals(Object other)
      Returns true iff the parameter is a numerically equivalent BigInt.
      Overrides:
      equals in class Object
      Parameters:
      other - the object being compared with this one.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(BigInt other)
      Returns true iff the parameter is numerically equivalent.
      Parameters:
      other - the BigInt being compared with this one.