Question: class Binary: If you use any method you have defined in another method definition, use the overloaded operator, if there is one. For instance, you

class Binary: If you use any method you have defined in another method definition, use the
overloaded operator, if there is one. For instance, you will lose points if we see anything like
bin1.__add__(bin2). This should be bin1+ bin2. Decorate your class with the
functools.total_ordering decorator.
init: init has one string parameter with a default argument of '0'. This string can be the empty
string (treat the same as '0'). Otherwise, it should consist only of 0s and 1s and should be 16 or less
characters long. If the argument does not meet these requirements, raise a RuntimeError. Each
Binary object has one instance variable, an integer array of length 16 called bit_array.
bit_array has integers 0 or 1 in the same order as the corresponding characters in the argument. If
the string is less than 16 characters long, bit_array should be padded on the left with the leftmost
digit in the string (intified, of course). You may not use lists in this method.
eq: Takes a Binary object as an argument. Return True if self == the argument, False
otherwise. You may not use int in this method. Do this one after init many of the tests won't work
until this one passes.
repr: Return a 16-character string representing the fixed-width binary number, such as:
'00000000000000000'.
add: Takes a Binary object as an argument. Return a new Binary instance that represents the sum
of self and the argument. If the sum requires more than 16 digits, raise a RuntimeError. You may
not use int in this method.
neg: Return a new Binary instance that equals -self. You may not use int in this method.
sub: Takes a Binary object as an argument. Return a new Binary instance that represents self
the argument. You may not use int in this method.
int: Return the decimal value of the Binary object. This method should never raise a
RuntimeError due to overflow. Do not use this int on Binary objects in any other method. Do
not use the built-in int, either. You will probably need to use the item method on the integer that you
calculate to extract the regular Python int from the np.int32 instance that you have created.
lt: Takes a Binary object as an argument. Return True if self < the argument, False
otherwise. This method should never raise a RuntimeError due to overflow. You may not use int
in this method.
abs: Return a new instance that is the absolute value of self. You may not use int in this method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!