Class Bit

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Bit ONE
      The bit 1.
      static Bit ZERO
      The bit 0.
    • Constructor Summary

      Constructors 
      Constructor Description
      Bit​(boolean bit)
      Initialize this bit to 1 if bit is true, and 0 otherwise.
      Bit​(int bit)
      Initialize this bit to the specified value.
      Bit​(Bit other)
      Initialize this bit by copying another bit.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Bit and​(Bit other)
      Sets this bit to the logical AND of this bit and the other bit.
      int compareTo​(Bit other)
      Compares this bit to another bit for order.
      boolean equals​(Object obj)
      Compares this bit to an object for equality.
      int hashCode()
      Returns a hash code for this bit;
      Bit not()
      Sets the value of this bit to 0 if the current value of this bit is 1, or sets the value of this bit to 1 if the current value of this bit is 0.
      Bit or​(Bit other)
      Sets this bit to the logical OR of this bit and the other bit.
      Bit set​(boolean bit)
      Sets this bit to 1 if bit is true, 0 otherwise.
      Bit set​(int bit)
      Sets this bit the specified value.
      String toString()
      Returns the string representation of this bit ("0" or "1").
      int value()
      Get the value of this bit (0 or 1)
    • Field Detail

      • ZERO

        public static final Bit ZERO
        The bit 0.
      • ONE

        public static final Bit ONE
        The bit 1.
    • Constructor Detail

      • Bit

        public Bit​(boolean bit)
        Initialize this bit to 1 if bit is true, and 0 otherwise.
        Parameters:
        bit - the value of the bit
      • Bit

        public Bit​(int bit)
        Initialize this bit to the specified value.
        Parameters:
        bit - the value of this bit
        Throws:
        IllegalArgumentException - if bit is not equal to 0 or not equal to 1
      • Bit

        public Bit​(Bit other)
        Initialize this bit by copying another bit.
        Parameters:
        other - the bit to copy
    • Method Detail

      • value

        public int value()
        Get the value of this bit (0 or 1)
        Returns:
        the value of this bit
      • set

        public final Bit set​(boolean bit)
        Sets this bit to 1 if bit is true, 0 otherwise.
        Parameters:
        bit - the value of this bit
        Returns:
        a reference to this Bit
      • set

        public final Bit set​(int bit)
        Sets this bit the specified value.
        Parameters:
        bit - the value of this bit
        Returns:
        a reference to this Bit
        Throws:
        IllegalArgumentException - if bit is not equal to 0 or not equal to 1
      • not

        public Bit not()
        Sets the value of this bit to 0 if the current value of this bit is 1, or sets the value of this bit to 1 if the current value of this bit is 0.
        Returns:
        a reference to this bit
      • and

        public Bit and​(Bit other)
        Sets this bit to the logical AND of this bit and the other bit. Sets this bit to 1 if this bit and the other bit values are both 1, otherwise sets this bit to 0.
        Parameters:
        other - another bit
        Returns:
        a reference to this bit
      • or

        public Bit or​(Bit other)
        Sets this bit to the logical OR of this bit and the other bit. Sets this bit to 0 if this bit and the other bit values are both 0, otherwise sets this bit to 1.
        Parameters:
        other - another bit
        Returns:
        a reference to this bit
      • hashCode

        public int hashCode()
        Returns a hash code for this bit;
        Overrides:
        hashCode in class Object
        Returns:
        a hash code for this bit
      • equals

        public boolean equals​(Object obj)
        Compares this bit to an object for equality. Returns true if and only if obj is a Bit with the same value as this bit.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare
        Returns:
        true if this bit is equal to obj, false otherwise
      • compareTo

        public int compareTo​(Bit other)
        Compares this bit to another bit for order. Returns 1 if this bit is 1 and the other bit is 0, -1 if this bit is 0 and the other bit is 1, and 0 otherwise.
        Specified by:
        compareTo in interface Comparable<Bit>
        Returns:
        1, -1, or 0 if this bit is greater than, less than, or equal to the other bit
      • toString

        public String toString()
        Returns the string representation of this bit ("0" or "1").
        Overrides:
        toString in class Object
        Returns:
        a string representation of this bit