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
binaddbin This should be bin bin Decorate your class with the
functools.totalordering decorator.
init: init has one string parameter with a default argument of This string can be the empty
string treat the same as Otherwise, it should consist only of s and s and should be 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 called bitarray.
bitarray has integers or in the same order as the corresponding characters in the argument. If
the string is less than characters long, bitarray 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 character string representing the fixedwidth binary number, such as:
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 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 builtin 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 npint 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
