a) Consider the function, bin, that converts an integer to a binary digit as:
bin : Z 6{-1, 0, 1}, bin(x) = x congruence modulo 2.
Now, define the logical NOT function as:
NOT: Z"\\to" {0, 1}, NOT(x)="\\begin{Bmatrix}\n 0, if x != 0\\\\\n 1, if x=0 \n\\end{Bmatrix}"
i) Write C++ code for the logical NOT function specified above.
ii) Using the function defined in i) above, write in C++ the polymorphic logical exor
function:
int exor(int x, int y):- it returns x r y
int exor(int * bits, int N):- it returns the exor of the N binary integers, bits.
b) As a result of a) above, write in C++ the polymorphic logical not exor function,
nexor:
int nexor(int x, int y):- it returns the negation of x r y
int nexor(int * bits, int N):- it returns the nexor of the N binary integers, bits
Comments
Leave a comment